简体   繁体   中英

File is not running more than 5minutes even i set maximum_execution time in php file and php.ini file

I really don't know what exactly happens. I am running a file in which there is for loop and it reads the xml file which contains more than 11,000 items and i am inserting and updating the file in the website. When i run the script it is not executing more than 5 minutes. I googled the solution and found below answers:-

1.)ini_set('max_execution_time', 56700);
2.) ini_set('max_execution_time', -1);
3.) ini_set('max_execution_time', 0);
4.) in php.ini max_execution_time  = 600//10minutes

i also made a file phpinfo.php where i used the phpinfo function and it is displaying the maximum execution time =600//10 minutes but still my server is not executing it more than 5 minutes. I added time in my code to check for it.

I also added ini_set('memory_limit', '1G'); to check if there is no memory limit problem but still no resolve

Please help me. ALso note that safe mode is off

You can work around this problem with set_time_limit() . Set that for every iteration of a loop and you should be fine. You can set the time limit to a few seconds (enough to execute one iteration of your loop). I have used that for scripts that ran for more than an hour, and it worked just fine.

For example, like this:

while(1) {
    set_time_limit(5);
    // do something complicated for less than 5 seconds
    // break your loop eventually
} 

The big benefit of this approach is that you don't need to constantly tweak your settings for larger files, and that you can keep the timeouts where no large timespans were intended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM