Home>Article>Backend Development> php reports errors and records them by itself

php reports errors and records them by itself

尚
Original
2019-11-01 14:52:27 2342browse

php reports errors and records them by itself

We usually analyze errors through the nginx error log, which is the error_log we define in each server. Let's take a look at how PHP records errors by itself.

php records errors by itself:

We only need to customize an error log function in the program, and then, in The corresponding judgment is made in the program. If the program is not executed successfully, the error log function is called.

Customize the error log format and record the log:

1. Write the corresponding program in the program

 date("Y-m-d H:i",time()),//记录错误发生的时间 'error' => urlencode($data),//防止中文乱码 'order'=> $order,//记录订单 'user_name'=> $uid,//记录当前用户 ); //判断文件大小,选择追加还是重新写入,注意之前防止乱码用了urlencode if( abs(filesize($error_path)) < 10240 ){ @file_put_contents($error_path, urldecode(json_encode($error_data))."
",FILE_APPEND); }else{ @file_put_contents($error_path, urldecode(json_encode($error_data)) ."
"); }; } //模拟订单录入错误时,将日志记录到错误日志中 $uid = 1000070;//模拟用户uid $order = 2132215641000070;//模拟用户订单号 if (true) { set_debug($uid,$order,'订单录入失败'); }

2. Create the error file and grant permissions

cd /data/www

touch order.error.html

chmod 777 order.error.html

Recommended:phpserver

The above is the detailed content of php reports errors and records them by itself. 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