Using Crontab with Plesk to call PHP files (drupal – joomla – etc )

Using Crontab with Plesk to call PHP files (drupal – joomla – etc )

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:

Setting up Crontab from within Plesk to load a php file.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

seven − six =

This site uses Akismet to reduce spam. Learn how your comment data is processed.