How to deal with php website error 500
PHP program syntax error leads to
Scenario 1:
The project is set up with alarm monitoring ( Regularly access a fixed link on the website every 10 minutes). There was a time when I would receive emails reporting 500 errors two or three times a day, but when I manually accessed it again, the access was normal...
This should be It is the most common error, and grammatical errors can also reappear quickly. As long as the error message is exposed, the problem can be solved immediately. If it is in a local or test environment, we usually handle it like this. Just set the output error message in the program entrance:
//error_reporting设置应该报告的错误,下面表示除了 E_NOTICE,报告其他所有错误 error_reporting(E_ALL ^ E_NOTICE); //输出错误 ini_set('display_errors', 1);
But in an online environment, because all users are using it, it is impossible to allow us to So what should I do if there is a blatant printing error? You can set the error output to the log file in the program entry file. The specific code is as follows:
error_reporting(E_ALL ^ E_NOTICE); //禁止把错误输出到页面 ini_set('display_errors', 0); //设置错误信息输出到文件 ini_set('log_errors', 1); //指定错误日志文件名 $error_dir = '/logs/err/'; $error_file = $error_dir . date('Ymd').'.log'; //目录不存在就创建 if (!is_dir($error_dir)){ mkdir($error_dir, 0777, true); } //文件不存在就创建之 if(!file_exists($error_file)){ $fp = fopen($error_file, 'w+'); if($fp){ fclose($fp); } } //设置错误输出文件 ini_set("error_log", $error_file); //程序正常执行逻辑......
The problem in scenario 1 just mentioned was discovered later when we output it to the log in the same way as above. It was because mysql The connection was abnormally disconnected and the program continued to execute (it was normal when connecting to mysql, but an error was reported when calling the specific query method. I remember it seemed to be where the method mysqli_real_escape_string() was used). This resulted in a fatal error, which was finally successfully repaired.
The disk is full causing
Scenario 2:
The picture cannot be uploaded and error 500 is always reported.
500 errors caused by insufficient disk space and insufficient space to read and write data are extremely uncommon and difficult to detect in time. Usually when encountering a 500 error, the first thing that comes to mind is a program error. In fact, it may also be due to insufficient disk space. If you cannot find any problems in the program, you can check whether it is due to insufficient disk space.
df -h 查看磁盘空间占用情况
Recommended tutorial: PHP video tutorial
The above is the detailed content of How to deal with php website error 500. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

Validator can be created by adding the following two lines in the controller.
