dqwr32867 2015-10-27 05:43
浏览 43

插入批量记录时脚本过期

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 .

  • 写回答

1条回答 默认 最新

  • drdl18946 2015-10-27 06:23
    关注

    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).

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能