HowTo – Turning Off PHP Error Reporting Logs

Filed under: Site Management

Error reporting is the best way to get feedback on whether your script is performing correctly however in some cases a script can choke based on something that is out of your control and then the result is a log on your website host.

I run into this problem a lot when trying to post to Twitter through a plugin.

When twitter decides that the site is starting to get overloaded the first thing that they do is throttle API calls this means your script can not complete the tweet and thus you get another line added to your error_log file which usually shows up in your root directory.

Although it may be interesting to know when your tweet didn’t complete after deleting log after log of the same garbage it can get tiring.

Turning Off Logging

You can turn off all reporting in your php ini file however this is probably not the smartest thing to do. A better way to approach this would be to find the insulting plugin and place a line that will turn off reporting in that file.

This will allow your other scripts to provide error information but that one plugin you just can’t do anything about because if you manually edit it you will wipe it away in the next update only needs one line added which you can complete pretty quick… then go to the plugin writers site and tell them to catch errors…

Twitter is just one example .. scripts that behave correctly but sometimes choke and have been diagnosed can have these errors turned off … it will allow your site to continue working for the most part… and won’t result in huge files if your site gets a lot of activity.

[php]
<div>
<div><code> <?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings …)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set(‘error_reporting’, E_ALL);

?> </code></div>
</div>
[/php]

Remember even on shared hosting plans cPanel will usually allow you to generate your own php ini file so if things get hectic .. you can turn off errors until you fix things… just remember that errors are not a good thing and you need to fix what is wrong even if it means intercepting or jumping over errors that you can not control.