简体   繁体   English

PHP中的飞行错误报告

[英]On the fly error reporting in PHP

When our site used to be on IIS hosting with PHP installed, I had error reporting set to E_NONE and was able to turn it on temporarily by using: 当我们的网站曾经在安装了PHP的IIS主机上时,我将错误报告设置为E_NONE并且能够通过使用以下方式临时打开它:

ini_set('display_errors', 1);

That command seems to no longer work now that we are on Linux/Apache hosting. 现在我们在Linux / Apache托管上,该命令似乎不再有效。 I have tried purposely sending bad commands to the server and I get no errors reported. 我试图故意向服务器发送错误的命令,我没有报告错误。

What am I doing wrong? 我究竟做错了什么? Is there any other way to temporarily turn on error reporting without having to edit the php.ini each time? 有没有其他方法可以暂时打开错误报告,而无需每次都编辑php.ini?

You can change error reporting to E_ALL using the following line: 您可以使用以下行将错误报告更改为E_ALL

error_reporting(E_ALL);

Try adding that to the file. 尝试将其添加到文件中。

The best way to turn on all errors is: 打开所有错误的最佳方法是:

error_reporting( -1 );

This is better than E_ALL, as E_ALL doesn't actually mean all errors in all versions of PHP (it only does in the most recent). 这比E_ALL更好,因为E_ALL实际上并不意味着所有PHP版本中的所有错误(它只在最近的版本中发生)。 -1 is the only way to ensure it's on in all cases. -1是确保在所有情况下都启用的唯一方法。

I just had to do this in one of my scripts. 我只需要在我的一个脚本中执行此操作。 DOMDocument warnings were killing my logs. DOMDocument警告正在查杀我的日志。 So, here's what you do: 那么,这就是你做的:

// First, grab a copy of the current error_reporting level
// while setting the new level, I set it to zero because I wanted
// it off - but you could easily turn it on here
$erlevel = error_reporting(0);
// Then, do stuff that generates errors/warnings
// Finally, set the reporting level to it's previous value
error_reporting($erlevel);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM