Home >Backend Development >PHP Problem >php reports 500 error

php reports 500 error

angryTom
angryTomOriginal
2019-10-31 16:45:304268browse

php reports 500 error

php reports 500 error

For http request error status code is 500, the usual explanation is: it means that the server has encountered An error occurred and the request could not be completed (ie, an internal server error). However, specific problems need to be analyzed in detail. Here are some 500 problems and solutions.

1. PHP program syntax error leads to

Scenario 1: Our project is set up with alarm monitoring (regularly access a fixed link of the website every 10 minutes), once For a period of time, I would receive emails reporting 500 errors two or three times a day, but when I manually accessed them again, the access was normal...

This should be the most common error, and grammatical errors can also appear 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 the online environment, because users are using it , it is impossible to allow us to make such blatant printing errors, what should we do? 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);
//程序正常执行逻辑......

2. The disk is full causing

Scenario 2: Upload pictures, It keeps reporting an error of 500.

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 the 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 find any problems in the program, you can check whether it is due to insufficient disk space~

df -h Check the disk space usage

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of php reports 500 error. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more