简体   繁体   中英

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:

ini_set('display_errors', 1);

That command seems to no longer work now that we are on Linux/Apache hosting. 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?

You can change error reporting to E_ALL using the following line:

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). -1 is the only way to ensure it's on in all cases.

I just had to do this in one of my scripts. DOMDocument warnings were killing my logs. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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