views:

292

answers:

2

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

+4  A: 

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.

zombat
can i use set_time_limit(0); for a section of my script??
Pragati Sureka
Yes, you can use it anywhere.
zombat
@zombat but most of shared hosting not allow to edit php.ini setting and not support set_time_limit(0). In such situation, what will be the solution?
santosh
A: 

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

SooDesuNe
as commented above by santosh most shared hosting do not allow changing php.ini or the they block/do not support set_time_limit()... what can I do in this case...
Pragati Sureka