Fatal error: Maximum execution time of 30 seconds exceeded

    |
  • Added:
  • |
  • In: Basic PHP

I am downloading a JSON file from an online source and and when it runs through the loop I am getting this error:

Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\temp\fetch.php on line 24

This Question Has 15 Answeres | Orginal Question | Harsha M V

To extend your max_execution_time you can use either ini_set or set_time_limit.

// Set maximum execution time to 10 seconds this way ini_set('max_execution_time', 10); // or this way set_time_limit(10); 

!! But be aware that, both functions restarts also counting of time script has already taken to execute

sleep(2); ini_set('max_execution_time', 5); register_shutdown_function(function(){ var_dump(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']); }); for(;;); // // var_dump outputs float(7.1981489658356) // 

so if you want to set exact maximum amount of time script can run, your command must be very first.

Differences between those two functions are

  • set_time_limit does not return info whether it was successful but it will throw a warning on error.
  • ini_set returns old value on success, or false on failure without any warning/error

Edit php.ini

Find this line:

max_execution_time 

Change its value to 300:

max_execution_time = 300 

300 means 5 minutes of execution time for the http request.

you cando it easily with whm . jusst got to whm----->service configuration---------->php configuration editor-------max_execution_time----->30(it is default change it to whatever value u want)

Increase your script execution time by adding the following line at top of the PHP script.

ini_set('max_execution_time', 120); //120 seconds = 2 minutes 

Reference has taken from Increase the PHP Script Execution Time

You can remove the restriction by seting it to zero by adding this line at the top of your script:

<?php ini_set('max_execution_time', 0); ?> 

I ran into this problem while upgrading to WordPress 4.0. By default WordPress limits the maximum execution time to 30 seconds.

Add the following code to your .htaccess file on your root directory of your WordPress Installation to over-ride the default.

php_value max_execution_time 300 //where 300 = 300 seconds = 5 minutes 

Your loop might be endless. If it is not, you could extend the maximum execution time like this:

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

We can solve this problem in 3 different ways.

1) Using php.ini file

2) Using .htaccess file

3) Using Wp-config.php file ( for Wordpress )

For more details -> steptoinstall

I have same problem in WordPress site, I added in .htaccess file then working fine for me.

php_value max_execution_time 6000000 

if all the above didn't work for you then add an .htaccess file to the directory where your script is located and put this inside

<IfModule mod_php5.c> php_value post_max_size 200M php_value upload_max_filesize 200M php_value memory_limit 300M php_value max_execution_time 259200 php_value max_input_time 259200 php_value session.gc_maxlifetime 1200 </IfModule> 

this was the way I solved my problem , neither ini_set('max_execution_time', 86400); nor set_time_limit(86400) solved my problem , but the .htaccess method did.

Your script is timing out. Take a look at the set_time_limit() function to up the execution time. Or profile the script to make it run faster :)

May be check for any thing that you have changed under the php.ini file. For example I changed the ";intl.default_locale =" to ";intl.default_locale = en_utf8" in order to enable the "Internationalization extension (Intl)" without adding the "extension=php_intl.dll" then this same error occurred. So I suggest to check for similar mistakes.

I had the same problem and solved it by changing the value for the param max_execution_time in php.ini, like this:

max_execution_time = 360 ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE) max_input_time = 120 ; Maximum amount of time each script may spend parsing request data ;max_input_nesting_level = 64 ; Maximum input variable nesting level memory_limit = 128M ; Maximum amount of memory a script may consume (128MB by default) 

I hope this could help you.

All the answers above are correct, but I use a simple way to avoid it in some cases.

Just put this command in the begining of your script:

set_time_limit(0); 

Follow the path /etc/php5(your php version)/apache2/php.ini.

Open it and set the value of max_execution_time to a desired one.


Search
I am...

Sajjad Hossain

I have five years of experience in web development sector. I love to do amazing projects and share my knowledge with all.

Connect Social With PHPAns
Top