插入批量记录时脚本过期

I'm facing problem when I'm inserting bulk record from one table to another

so process is i have a csv that has bulk records i have used infile for that , that is working fine . Now i have to insert that records to another table with certain conditions on many field .

But while inserting records to the table script expire in 30 sec approx . below is what i already set .

set_time_limit(0);
ini_set('max_execution_time', 0);

and running phpinfo() shows

Directive           Local Value   Master Value

max_execution_time  0             60

max_file_uploads    20            20

PHP Version     5.3.3 

 CentOS 6.7 install

Thanks in advance for your help .

If you have access to your php.ini file, then correct its permission and edit it accordingly.

You can also create an empty php.ini in your public_html (root directory) and just add a line for maximum execution time.

But another way to handle maximum execution time is that, you can add to the default PHP timer using set_time_limit(), but not definitely in the very first line. It adds to the timer, it does not set a default value as does php.ini, also as PHP Documentation says, you cannot use in if php is run in safe_mode.

It is better, if after all you do not have access to php configuration, to handle your script using set_time_limit(). You can make a time utility manager for such purpose. Use set_time_limit() in the heart of your script when you think time is running out. For instance:

while(true)
{
  if(get_time_of_my_script() == 25) // assuming php.ini's limit is 30 seconds
  {
    set_time_limit(20); // add 20 more seconds
  }
}

function get_time_of_my_script()
{
   // write something that calculates your execution time from the 
   //  very first line till the invocation
   // of the function
}

Though you should bear in mind that:

  • All timing settings of php is limited to the PHP internally. If you execute a system() call then it is not under PHP's control until it returns something. Therefore, if you are dealing with DB, make sure about timing of DB engine.

  • Other environmental settings such as Apache/IIS timing settings would normally limit PHP after a certain length of time (though their default is 300 seconds which is adequate probably for you).