Having battled with getting a php file to be called from a scheduled task (a.k.a. a crontab task) using the Plesk interface panel on a Linux box, I thought I’d share a bit of a how-to on it because I struggled to find anything helpful out there on the topic.
Here is screen shot of a completed “Schedule New Task” form so that you can see what a working configuration looks like:
The fields on the form look fairly self explanatory to fill out, but the first gotcha for me was how to get it so that the job runs every hour instead of on just one named hour. To get the cron to run every hour you just need to use an asterisk (*), the same technique can be applied for all other time frequencies as well.
Once you’ve set the cron to run at the required interval, you will need to tell it what command to call. This isn’t obvious either. Firstly what you need to do is call php or state the path to the php folder, then pass it the parameter “-q” (to suppress the HTTP header output), and then state the full path of the php file that you want to run e.g.
php -q httpdocs/cron.php
If you just put the path to the name of the php file that you want to run, then the cron will throw an error.
For reference, I’m using Plesk 9.5.1 & PHP 5.3