i have a php script that should be run automatically every day. as the php script is run on a request,how can i do it? is there any way else using cronjob task?
-
Why you hate cronjob for this requirement?Shakti Singh– Shakti Singh2010-12-07 07:12:32 +00:00Commented Dec 7, 2010 at 7:12
-
Can you explain why the cron job is not fit here?Shakti Singh– Shakti Singh2010-12-07 07:41:03 +00:00Commented Dec 7, 2010 at 7:41
-
1Came down friends,i have no problem with using cronjob,i just want to know about the ways others use to do such job to improve my knowledge and getting new idea and finding better ways to do works.hd.– hd.2010-12-07 07:45:40 +00:00Commented Dec 7, 2010 at 7:45
5 Answers
Two options:
- Use crontab demon
- Hire a worker and make him open script in a browser every 24 hours
The choice is yours :)
To use crontab, type crontab -e in console, the text file opens. Add a line at the end:
0 0 * * * /usr/bin/php /var/www/mysite/httpdocs/daily_stats.php
Where:
0 0 * * * - run every day at 00:00
/usr/bin/php -path to your PHP (can be determined by which php command)
/var/www/mysite/httpdocs/daily_stats.php - path to your PHP script
if which php outputs nothing, install PHP cli by running:
sudo aptitude install php5-cli
Good luck!
Comments
If cron isn't available in some sort of way you could use Google app engine's cron for this. Because cron is the way to go.
Comments
If cron is not available you could execute a php script in CLI which will run all the time.
In the script you can make a infinite while loop.
In the while loop, check a file on disk or a db record (you can controll this file or db record from an external script, telling the looping script what to do (CLI execute another script at a given hour) and when to exit)
If you use a database,don't forget to initialize and close the db connection each time the loop runs.
I'd sleep the loop every 1 min or so.. you could use this instead of linux cron for many more things.