PHP error reporting

I’m self-taught when it comes to PHP, which is probably how a lot of people get there with a lot of languages these days, but what I mean is that I’ve never had any formal training on it and I’ve never worked with it commercially.  Most of my experience with it at the moment is with WordPress custom themes and plugins.

I recently had a client who got an email from their hosting provider saying that whilst their account was “unlimited” they were currently breaking the fair usage policy, due to one particularly large file.  A 42Gb “error.log” file.  Yes, that’s fourty-two GIGAbytes!

The first thing I did was delete the file – there’s no way I was going to wait for it to download and I highly doubted Notepad++ would be able to open it if I did.  Within 2 minutes, it was back to to 2.4Mb.

So what was going on?  Well, PHP had been updated on the server, and the CMS they were using (not WordPress in this case) was rather old, so there were literally thousands of PHP deprecation notices flooding into the log file.

In this case, they had the “phpinfo.php” file accessible (don’t do this!) so I could see that the error_reporting value was set to 32759, which I also knew was pretty high.  I was aware that this value was a bitmask, but after a fair amount of Googling, I was struggling to find a way to calculate the value I wanted in an easy way.

That was until I found this PHP Error Reporting Calculator.

It does exactly what I wanted.  I could type in the 32759 and immediately see which levels were set (all except E_NOTICE and E_ALL) and then I could switch off the ones I didn’t want (E_STRICT, E_DEPRECATED, E_USER_DEPRECATED) and get the value I needed, which was 6143.

I added this to the .htaccess file, like this…

php_value error_reporting 6143

And that was it.  Obviously I’ve warned the client that this is a short term fix and they really need to upgrade to a more modern CMS, but at least they’re not at risk of having their website taken offline completely, just yet!