Website Scripts And Cloud Tutorials

How to change max_execution_time php during runtime

Byadmin

Mar 23, 2014 ,

Last updated on February 22nd, 2022 at 01:32 pm

Click to rate this tutorial!
[Total: 0 Average: 0]

Change maximum execution time in PHP temporarily is always a good idea since you can dynamically change the execution time of a particular php file. According to php.net, max_execution_time sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.

Sometimes developers need to override the default setting of 30 seconds to say 120 seconds. How to do this? It is simple you just need to define ini_set() before calling any of your code. That means this should be done in the header after the <?php opening tag.

Points To Be Noted
Here we have changed the max_execution_time to 120 seconds. This does not change the server configuration in php.ini file, It will just override the default execution time with the defined one for that particular script only.

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini

<?php
ini_set('max_execution_time','120');//Default 30 seconds
//Rest of you code goes here
?>

The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

Click to rate this tutorial!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published.