OpenCart Automatic Error Log Trimmer

Posted by Paul on March 4, 2016

I blogged some time ago about a very elusive but dangerous beast of a problem that can happen to unsuspecting OpenCart sites. Essentially, the built-in Error Log file never clears itself and will continue to grow unless manually cleared. Much like the guests a house party with endless supplies of alcohol, PHP has become much more verbose lately and spits out warnings and notices at any code it finds even slightly questionable.

It's a good thing really that many web hosts automtically update PHP versions, but what happens behind the scenes is that PHP starts spitting out ever more little messages to your system log. Most of these message won't show on the website at all because they're classed as "Notices" or "Warnings" rather than "Fatal Errors". So these keep getting added to your system log file. We're not talking about the occasional message here of course, it's likely that several messages will be generated for every single page load.

In a cruel, ironic twist, it may be entirely safe to ignore most or even all of the messages that are being written to the system error log. Over time however, it can grow to dangerous levels - in fact, I've seen the error log file grow to a whopping 2 Gigabytes. That's a lot of errors!

The first issue of course is disk space on your server. If this runs out, you're likely to experience some issues. If you're very unlucky, you might find that PHP has no space to store session files. Without those, your users wont' be able to add anything to their cart or log in. Pretty bad, but there's worse! Depending on how much memory your server has, you'll probably  find that when the error log reaches that limit, the site just turns in to a white screen of death - a blank page that offers no clues what has happened.

The first thing your web developer will do in thise case, assuming you can contact them and it's not the weekend of course is ask the host to get error messages turned on. If the host replies quickly and knows what they're doing (which is rare but always nice when it happens) you'll only see a "500 Internal Server Error" message. This doesn't tell the developer, or the host anything, so it will almost certainly take them a considerable amount of time to realize (if they even find the issue) that the error log has grown beyond the server memory limit.

But of course, there's a solution! Our latest OpenCart module will periodically check your error log file and trim the oldest messages when it's still nowhere near big enough to cause any issues. In an ideal world, none of your themes or extensions would generate any notices, warnings, or errors but in reality, they sometimes do and having an extension like this can prevent some very stressful and lengthy downtime where nobody can figure out the actual issue!

So save yourselves, your developers and your web host some grey hairs and install our automatic log trimming extension today by clicking here.

blog comments powered by Disqus