![](/img/trans.png)
[英]Log errors, and instead of displaying them, show a 500 Error Page in PHP
[英]How to disable displaying of errors in php and log them in a file
我正在尝试禁用文件中的错误显示,仅将其记录到日志文件中
<?php
error_reporting('E_ALL');
echo $x;
?>
当我删除error_reporting('E_ALL')时,日志文件有效,但同时还会显示错误。 还有另一种方法可以执行此操作,但是仅在特定页面上禁用错误报告。
您可以创建一个自定义错误处理函数,并通过set_error_handler()
:
set_error_handler(function($errno, $errstr, $errfile = null, $errline = 0, $errcontext = null)
{
// Append $errstr and other useful information to a file
@file_put_contents('error_log', "ERROR: $errstr\n", FILE_APPEND);
return true; // disable regular PHP error reporting
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.