petesiss
petesiss

Reputation: 994

php script that calls itself when it is finished - indefinately

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.

Upvotes: 4

Views: 2091

Answers (3)

timdev
timdev

Reputation: 62894

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.

Upvotes: 1

David Young
David Young

Reputation: 4743

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/

Upvotes: 7

Daniel Egeberg
Daniel Egeberg

Reputation: 8382

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

Upvotes: 2

Related Questions