5

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)
7
  • Maybe it runs out fo memory. Does you php cli environment have enough memory assigned? Commented Jun 7, 2011 at 9:03
  • Something useful in $HOME/log? Commented Jun 7, 2011 at 9:06
  • 2
    set execution time longer => max_execution_time : Maximum execution time of each script, in seconds (default 30 seconds) => max_input_time : Maximum amount of time each script may spend parsing request data (60 seconds) => memory_limit : Maximum amount of memory a script may consume (default 8MB) Commented Jun 7, 2011 at 9:07
  • Have you checked your php error log? Commented Jun 7, 2011 at 9:15
  • 1
    You are running this command every 3 minutes. Does one run of the script take longer than 3 minutes? If so, maybe one run is disturbing the previous one. Commented Jun 7, 2011 at 9:18

2 Answers 2

4

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?

Sign up to request clarification or add additional context in comments.

2 Comments

When I run it from command line it takes less than a second to complete. I can't imagine why it would take it more than 3 minutes to run via cron.
you called it ./release.php when trying directly, maybe there is a problem with include paths? change your cronjob to do the same: cd /var/www/vhosts/example.com/ && ./release.php
0

Either ensure that your script is only running one at a time or output your results to uniquely named log files (which is probably better since you'll want to be able to review past executions).

*/3 *  *   *   *     /var/www/vhosts/example.com/release.php &> $HOME/release-$(date "+%Y%m%d%-%H%M%S").log

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.