Workaround for cron time limits

So, basically I use the cron job to execute the php script, which takes quite a lot of time to execute (pulling the updated xml from ftp, unpacking, mysql manipulation, api access, etc.). The problem is that we are working on a server that limits the cron job execution time to 15 minutes.

My question is this: what methods can be used to eliminate this limitation? Breaking the script to pieces will still cause the pieces to work for a 15-minute period, so it will. Are there any ways to redirect to another PHP script after execution for a certain time? Or is it possible to somehow use a bash script to restart the script before reaching the 15 minute deadline?

Thank!

+3
source share
3 answers

My first tip is to find a new host, but it seems like this is not an option for you right now.

You can track the runtime and save your status in a DB or flat file just before you press the 15 minute deadline. The next round in cron would then look at the database or file and know where to get where you left off.

It depends on what your script does, of course. If you just perform the same task for the X number of records, it sounds as if you can implement something like this.

+2
source

, , . exec() script - , .

"" a script. , .

, ? 15 , cron ? , -, . 15 , . , , 15 .

, , , cron, cron wget script .

0

cron script. -

 0 0 * * * php /path/to/file.php &

, cron, , script cron

0

Source: https://habr.com/ru/post/1790262/


All Articles