Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php script that calls itself when it is finished - indefinately

Tags:

php

cron

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.

like image 774
petesiss Avatar asked Dec 29 '22 09:12

petesiss


2 Answers

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/

like image 179
David Young Avatar answered Jan 08 '23 02:01

David Young


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

like image 43
Daniel Egeberg Avatar answered Jan 08 '23 01:01

Daniel Egeberg