HIRE US

Let us help you with your Drupal requirements

To prevent automated spam submissions leave this field empty.

We had recently faced an issue in one of our client's website running on Drupal 5. The site had crashed and we were unable to continue development. We began analyzing the problem by checking the free space on the site and came to the conclusion that the now deprecated PHP Ereg function was causing the site to crash. If you are facing the same issue in one of your Drupal sites, read on to know how we successfully fixed the bug.

First let us explain how we found the bug. We began by checking the free space on the website and found that more than 50% space was still available. Then we checked the database and we found that the watchdog table had become corrupted. We truncated the table and it actually started working!

We may not have actually gone for truncating the table, since it was a watchdog table. But the issue was due to the corrupted table. We also realized that a few pages that were working, no longer worked. They were all showing WSOD and we found around 20 pages of warning messages recorded in a short duration of time. Interestingly, they were all generated around a PHP ereg function.

elseif ($depth >= $min_depth && ereg($mask, $file)) {

We have also noticed that the server was upgraded recently from 5.1 to 5.3. Then we had a look into the PHP manual for ereg and noticed the following warning about function.

"This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged."

We realized that the solution to this problem was to replace it with preg_match which is somewhat similar to ereg and supported by PHP. Here is how we did it.

example code

// Original code
elseif ($depth >= $min_depth && ereg($mask, $file)) {
// Replaced code.
elseif ($depth >= $min_depth && mb_ereg($mask, $file)) {

// Original code
if(!ereg("^[A-Za-z0-9\-|_]*$", $name))
// Replaced code.
if(!preg_match("/[^A-z0-9_\-]/", $name))

This fixed the issue caused by ereg function which is deprecated after php 5.3. Hope this article was helpful to you too.

Post your comments / questions