tags:

views:

48

answers:

3

I have a php script that can take anything from 2 to 10 minutes to execute. It fetches info from around the web so its time depends on how fast lots of other things are talking.

I used to run the script on a cron every 15 minutes, but sometimes it only takes 2 minutes to run.

So I wondered if I can somehow make it run perpetually - setting itself going again as soon as it finishes its task? That way, however long it takes, it will always start agaiun straight away.

+2  A: 

Put the entire thing in an infinite loop? Either in the PHP code itself, or make a launch script that does that.

Daniel Egeberg
theres always a limit on how long a php script can execute for, so it needs to properly exit and start again i think.
Those execution limits may be disabled. See, eg., [max_execution_time](http://php.net/max-execution-time).
ladenedge
ah, cool. i'll look in to that. thanks.
+5  A: 

Seems like you're running into cron job issues. I would instead turn your script into a daemon, that way it can run perpetually without fear of overlaps or finishing too fast.

Here's a tutorial how to do it.

http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/

David Young
ah, great. thanks for the link. that sounds like just the ticket.
+1  A: 

Writing a daemon is probably the best solution.

If you're lazy, and on linux/unix, you can just script an infinite loop, and set it running inside a screen session.

timdev
hey - thanks. Looks like another good option.