I have written a PHP code to do some processing on data, but before the processing can finish, the script throws an error ‘Fatal error: Maximum execution time of 30 seconds exceeded in /home/dales/public_html/processbulkdata.php’.
- Dale

To change the maximum execution time of a PHP script you need to use the ‘set_time_limit‘ function. The function takes one argument which is the maximum number of seconds a script is allowed to run. If seconds is set to ‘0′, no time limit is imposed on the script and it may run indefinitely. Use the following snippet just before your time consuming code begins:

Note that, if you set the number of seconds to a value very high, you may recieve the fatal error just after 1 second. Its better to use ‘set_time_limit(0)‘ instead. Also, remember that when you are finished with the portion that performs the busy computation, its a good idea to call:

so that the remaining portion of the script finishes in 30 seconds or fatal error is thrown.

5 Responses to “Modify maximum execution time of a PHP script”

  1. videodownloader Says:

    this tip is great..
    i have a video website which load video and pass it to browser by php.. an it some time take more that 30s ..
    now i can change the time to 60s which make sure all run better..
    thanks for tips.
    – this used here
    http://www.mtvvui.com/videodownloader.php

  2. ninware Says:

    Great PHP tips thanks :)

  3. pradeep Indika Says:

    Really helpful. thank you!

  4. dayg Says:

    Great tip. Thanks!

    I will need this for some PHP cron stuff I’m currently working on.

  5. xyz Says:

    where should i write “set_time_limit(0)”

    for the error “Maximum execution time of 30 seconds exceeded in /home/data/users/m/mmm/m1/classes/http.php on line 427″

Leave a Reply