Home  >  Article  >  Backend Development  >  PHP reports internal 500 error

PHP reports internal 500 error

尚
Original
2019-11-01 14:31:105809browse

PHP reports internal 500 error

For http request error status code is 500, the usual explanation is: it means that the server encountered an error and was unable to complete the request (ie, internal server error)

Recommendation: php server

PHP program syntax error leads to

This should be the most common error, syntax errors can also reappear quickly, as long as the error is reported Once the information is exposed, the problem can be solved immediately.
If it is in a local or test environment, this is usually how we handle it. 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. What should we do if we are allowed to make such blatant printing errors? 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 disk is full causing

There is not enough space due to insufficient disk space. 500 errors caused by reading and writing 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 cannot find any problems in the program, you can check whether it is due to insufficient disk space.
df -h View disk space usage

PHP reports internal 500 error

The above is the detailed content of PHP reports internal 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