PHP Fatal error: Maximum execution time exceeded

  • Posted on: 18 December 2015
  • By: Michael

Problem: Your PHP max execution time was exceeded and PHP quits.

Solution: Extend PHP's Runtime Configuration max_execution_time.

For security reasons try changing max_execution_time to 60 seconds first, then longer if you need it.

* Also, you'll need to change the pathing I've used as appropriate for you site / system.

# Drupal Solution Details #

First we need to play, "Where's php.ini?"

:WHM (cPanel):

Goto: Service Configuration » PHP Configuration Editor
Edit: max_execution_time
Click: Save

cPanel makes life easy. You can skip the rest of this.

:Drush:

If you have Drush, go to your site's directory:

$ cd [YourDrupalInstallDir]
$ drush status

Look for the line "PHP configuration," which will tell you where your php.ini is. Here's a couple examples:

PHP configuration      :  /etc/php.ini
PHP configuration      :  /usr/local/lib/php.ini

:Command line:

If you don't have Drush, give these paths a shot:

/etc/php.ini
/etc/php5/apache2/php.ini
/private/etc/php.ini
/usr/lib/php.ini
/usr/local/lib/php.ini
/usr/local/php5/lib

or use:

$ locate php.ini

:Webserver:

To be definitive add a phpinfo file to your webserver

<?php
 
phpinfo();
 
?>

and open it ( http://{yourserver.com}/somename.php ) and find the section "Loaded Configuration File."

Let's Edit

Yeah, finally . . .

$ grep execution /etc/php.ini
max_execution_time = 30

Switch to root, make a backup, edit, and you're good. Here's a command line example of how to do that:

$ su -
$ cd /etc
$ cp  php.ini  php.ini.[Today'sDate]
$ nano  php.ini
[Crtl W]
max_execution_time
[Crtl K]
[Crtl U]
[Crtl U]
{comment out first line by adding ; to be beginning of the line}
{change second line to 60}
[Crtl X]
y

Your lines will look something like this before you save:

; Maximum execution time of each script, in seconds
; http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time
; max_execution_time = 30
max_execution_time = 60

Can't edit your php.ini?

Alternatively if you can't edit your php.ini, add

ini_set('max_execution_time', 60);

to your settings.php

$ cd [YourDrupalInstallDir]/sites/default
$ chmod +r settings.php
$ nano settings.php
{add ini_set above, preferably to the bottom so other developers will see it}
[Crtl X]
y
 
$ chmod -r settings.php

Do you need to restart Apache after changing the php.ini file?

Maybe. Depends. What a cop our right?

It really does depend on how your system is setup, so to be safe, just restart Apace and you should be good.

Best,
Michael

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
You know what to do... An image you see? there is one finger less than two hands of items to find. (We sincerely apologize for using image CAPTCHA, hint go low, and bots suck...)
Image CAPTCHA
Enter the characters shown in the image.