Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP script doesn't complete when run from cron

Tags:

php

cron

I have a PHP script that goes through all products in the database and looks at session files to see which products are in users' baskets. Then it releases stock which is allocated to baskets but the sessions for those baskets have expired. Simple enough.

For every product in the loop it prints out the product ID.

If I run the script from command line:

./release.php

It runs through all the products (~2500). However, if the script is run by crontab, it goes up to somewhere between 150 and 300 products; then it stops without any errors.

crontab -l
# m h  dom mon dow   command
*/3 *  *   *   *     /var/www/vhosts/example.com/release.php &> $HOME/release.log

There's nothing useful in /var/log/cron.log, either:

Jun  7 10:00:01 xxxxxxx /USR/SBIN/CRON[15751]: (root) CMD (/var/www/vhosts/example.com/release.php &> $HOME/log)
like image 512
Pawel Decowski Avatar asked Oct 11 '22 19:10

Pawel Decowski


1 Answers

Are you sure it's stopping? You execute the script every 3 minutes, and on each call you "reset" the logfile. (>file instead of >>file)

Do you use some kind of locking mechanism to prevent the script to start if it is already running?

like image 59
Rufinus Avatar answered Oct 14 '22 05:10

Rufinus