Cron jobs are used to run scripts on scheduled times on the server. Cron jobs are configurable in the Control Panel. If a Technical Contact is set for your Bolts, any errors or output from the cron jobs will be sent to the Technical Contact’s email.
Good cron tips
- Run scripts directly using PHP or sh, instead of triggering scripts over HTTP (by using
- 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).
- Test your crons manually to make sure they’re working as intended. For WordPress for example with
wp cron event run --all --path=/kunder/user_6258/site_19172/public
(this is an example path, check your Bolt and site settings for the correct path).
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:
If you need help in figuring out the cron schedule, this resource should be very helpful.
Errors and Debugging in Cron Jobs
When cron jobs produce any error output, an email will be sent to the Bolt’s Technical Contact, if that is set for your Bolt. In addition, cron logs any error output to a
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 login via SSH and execute the scripts. Then any error output will be posted directly to the screen.
Give us your feedback on this article
Did this help you?
Want to speed up your site, easily?
Set up your site on Servebolt, free of charge for 60 days, and see for yourself how fast it can be on our extremely fast hosting.
A faster site converts better, ranks better on Google, and is better for the climate.