Theresa Arzadon-Labajo

Drupal Search Module errors with php includes

Posted by Theresa Arzadon-Labajo (tarzadon) on Dec 07 2009
Tech Stuff >> Drupal
We have been experiencing intermittent Drupal White Screen of Death's when using the Search Module.  At first, we thought it was multiple search terms that were causing this. But, even single term searches would fail.  It seems that it depended on the word being search, but I couldn't make a correlation.

I looked in error_log and it was showing a 500 error.  php.log was showing "PHP Fatal error:  Cannot redeclare mymail() (previously declared..."

I renamed the function, but I got the same error again for the new function name.  On one page node, I include a php file using the PHP filter module.

On http://drupal.org/node/32963, kiz_0987 said:
"Be careful with just using include. If you have 2 nodes that use the same function then viewing each separately will be OK, but anytime you view the two together (eg via taxonomy) or with cron.php you may get a redeclare error. Use include_once instead."

Also, javanaut said:
"I would suggest putting your code in a separate .inc file and including it from your settings.php file. The default settings file is in sites/default/settings.php. If you created the file sites/default/myfunctions.php, you could included it from settings.php as:
        <?php
include('myfunctions.php');
?>

This assumes that this directory is in PHP's include_path."

So, I took the function out of my include file and copied it into sites/default/myfunctions.php.  Instead of adding the include to settings.php, where it would be included everywhere, I added  "include_once('myfunctions.php');"  in my include file.

Drupal Search seems to work consistently now.

Last changed: Feb 27 2020 at 4:13 PM

Back