Home Articles Getting started How To add Cron Jobs to your Servebolt site

How To add Cron Jobs to your Servebolt site

Cron jobs are used to run scripts on scheduled times on the server. Cron jobs are configurable in the control panel.

If a tech contact is set for the host, any errors or output from the cron jobs will be sent to the tech contacts email.

Good Tips!

Run scripts directly using PHP or sh, instead of triggering scripts over http (by using wget, curl etc).

Run cron jobs as seldom as possible. This saves resources and reduces the workload on the server and databases.

If you run multiple cron jobs, make sure they do not overlap (use sleep for instance, see examples below).

Adding cron jobs

Time is specified in cron syntax. The following example runs the cron.php script in the public folder every fifth minute:

*/5 * * * * /usr/bin/php ~/public/cron.php

Add a second cron job that runs at the same intervals , but waits 30 seconds before it starts.

*/5 * * * * /usr/bin/sleep 30; /usr/bin/php ~/public/cron_job_2.php

Paths to normal commands:

Errors and Debugging in Cron Jobs

When cron jobs produce error output, an e-mail will be sent to the Hosts Technical Contact, if that is set for your host. In addition, cron logs any error output to logs/cron.log.

The most common reason for PHP based cron jobs is a memory limits. The PHP memory limit can be adjusted by calling your php script with the -d parameter like this: php -d memory_limit=512M script.php 

If there are other errors, the way to debug cron is to log in via SSH and execute the scripts. Then any error output will be posted directly to screen.

Did this help you?