Friday, October 23, 2009

PHP Cron Jobs - HowTo, Tips and Trick

How to set up PHP cron jobs?

To set up PHP cron jobs, there's two way to do:
- Using the /usr/bin/php /path/to/file.php command in your cron tab.
If you have access to CronJobs, you can simply enter that command into the "Command to execute" field.

But this way is not recommended, as your script may not run expected. It's difficult to parse some variable to the script, too.

- Set cron job to call its URL.
This is more convenient, and you can test whether your script executes as expected or not just by entering its URL into browser.
You can use the wget or lynx command to call that URL, and lynx is recommended, as it's a browser.

To set up PHP cron jobs with lynx, you can enter lynx with is PHP script's URL. You can also add some GET variable into the URL using ?var1=value[&var2=value2&....].
Or, you can try some free cron jobs services to set up your PHP cron jobs :) Most of them work perfectly, and have their own simple WebCron interface.

PHP Cron Jobs - Tips and Trick.
- To make sure your cron jobs run until finishing its jobs, you can try tips at Set cron jobs with PHP scripts.
- To prevent your cron script from running when you create / save / enable your cron at SetCronJob, read this tips.
- If you wanna set cron job every minute to do some small jobs, you can buy a cron every minute at price of $10 / year from SetCronJob.
- You may wanna build your own web cron service, and phpJobsScheduler is a good choice for you :)

No comments:

Post a Comment