Viewed   166 times

I have an XML document that has around 48,000 children (~50MB). I run an INSERT MYSQL query that makes new entries for each one of these children. The problem is that it takes a lot of time due to its size. After it is executed I receive this

Fatal error: Maximum execution time of 60 seconds exceeded in /path/test.php on line 18

How do I set the Maximum execution time to be unlimited?




You can make it by setting set_time_limit in you php code (set to 0 for no limit)


Or modifying the value of max_execution_time directly in your php.ini

; Resource Limits ;

; Maximum execution time of each script, in seconds
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 120  

Or changing it with ini_set()

ini_set('max_execution_time', 120); //120 seconds

but note that for this 3rd option :


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.


Friday, November 18, 2022
ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
ini_set('max_execution_time', '0'); // for infinite time of execution 

Place this at the top of your PHP script and let your script loose!

Taken from Increase PHP Script Execution Time Limit Using ini_set()

Friday, November 4, 2022

I would say just build it yourself. You can set it up like this:

$query = "INSERT INTO x (a,b,c) VALUES ";
foreach ($arr as $item) {
  $query .= "('".$item[0]."','".$item[1]."','".$item[2]."'),";
$query = rtrim($query,",");//remove the extra comma
//execute query

Don't forget to escape quotes if it's necessary.

Also, be careful that there's not too much data being sent at once. You may have to execute it in chunks instead of all at once.

Saturday, November 5, 2022

You have 3 options. My recommendation: Use cron if you can, user driven if you have to, and daemon as a last resort.

(1) cron (as mentioned in comments)

cron is a scheduler for linux systems that will run a command line job on your system. You log into your server over ssh, type crontab -e, and add a line like this:

4 5 * * * php /path/to/my/script.php

This would run the script at 5:04 a.m. every day.

// /path/to/my/script.php

// Do something

Some hosting services allow entering cron jobs with a GUI. There are also external cron services, that will call a URL for you at specific times.

(2) daemon

This is the most advanced option and also the least reliable: You run a command line script that contains an infinite loop. The script then periodically checks state and responds to it. Because it is likely to crash after months of running, you have to have a second script to restart it in case it does. This is a lot of work, but it is the most flexible approach.


while (1) {   

  // fetch $last_exec_timestamp from database

  if ($last_exec_timestamp < time() + 86400) {
    // set last_exec_timestamp to now in database

    // do something


3. user driven

If you have a decent amount of traffic on your site, you can simply include a the job this in your page footer, when there is no more output. Make sure this code is fast, or an unlucky user will be waiting for it.


// fetch $last_exec_timestamp from database

if ($last_exec_timestamp < time() + 86400) {
  // set last_exec_timestamp to now in database
  // do something

There are also to more fancy approaches of "user driven" that I haven't personally tested in another question.

Saturday, August 20, 2022

I have the same error, please go to


Look for : $cfg['ExecTimeLimit'] = 600;

You can change '600' to any higher value, like '6000'.

Maximum execution time in seconds is (0 for no limit).

This will fix your error.

Tuesday, October 11, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :