I'm having trouble running a single instance of a PHP script using CRON. Perhaps someone can help explain what is needed. Currenty, I have a startup script that is called by crontab which checks to make sure an instance of a PHP script isn't already running before calling the PHP instance.
crontab -e entry:
* * * * * /var/www/private/script.php >> /var/www/private/script.log 2>&1 &
./startup
#!/bin/bash
if ps -ef | grep '[s]cript';
then
exit;
else
/usr/bin/php /var/www/private/script.php >>/var/www/private/script.log 2>&1 &
echo 'started'
fi
This doesn't seem to be working and I can't seem to get any errors logged to know how to proceed to debug this.
You can use lockrun for that: http://www.unixwiz.net/tools/lockrun.html
* * * * * /usr/local/bin/lockrun --lockfile=/var/run/script.lockrun -- php /home/script.php
Or use Perl:
system('php /home/script.php') if ( ! `ps -aef|grep -v grep|grep script.php`);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With