How to deal with php website error 500

王林
Release: 2023-02-25 16:36:02
Original
3901 people have browsed it

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);
Copy after login

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);

//程序正常执行逻辑......
Copy after login

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 查看磁盘空间占用情况
Copy after login

How to deal with php website error 500

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!