开发者

executing php cURL script for long time without changing php.ini settings

开发者 https://www.devze.com 2022-12-17 20:16 出处:网络
Scenario I have a old blog on blogger that contains thousands of images and posts, i have already imported the posts from blogger to wordpress using their import service (which does not import images

Scenario

I have a old blog on blogger that contains thousands of images and posts, i have already imported the posts from blogger to wordpress using their import service (which does not import images) now i want to write a php cURL script that will download all the images off my old blogger blog to wordpress.

Problem

I have already written a script that goes through all the posts and find the image links of blogger and download the links recursively and store them local to wordpress installation but the problem is that the script stops if its taking longer than max_execution_time which is generally set to 30 secs. Now i dont want to change setting in php.ini file. Is there some way that i can keep my script executing for that long or some other alternative.... like executi开发者_开发百科ng in batch or something else...

Reason for not changing php.ini settings is that i want to release this script as opensource plugin for wordpress, and not many have access to their php.ini file on the server and and many don't like changing settings for just one script that might run just once.

Thank You for helping....


You can modify some ini settings at run time, so they only affect the current incarnation of the script. In this case, there's a special function, set_time_limit():

set_time_limit(0);

This will effectively remove the time limit on your script execution. All other scripts will be unaffected.


If you're able to call set_time_limit for some other, non-zero time, you can reset the time limit each time you iterate, since the timer is reset each time it's set.

Or, better said by the docs :

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

Just make sure you pick a sufficiently long time for each iteration to complete

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号