How does server cron work and why am I getting cron emails?

Server based cron can be used from the Control Panel. It is the preferred way to run background tasks for any website. That is because the alternative is to run such jobs in along with page loads that your visitors trigger. This may have both scalability and performance impacts.

When there’s an error in the cron job

The caveat when using server based cron is that if there’s something wrong, our servers will start sending you emails. These emails will contain the command executed on the server in the title, along with the output from the cron job.

The emails are meant for a technical person. That’s why the emails will be sent to the Technical Contact on your Bolt, if assigned. Otherwise, these messages will go to the Bolt owner.

The cron error emails can become excessive when something goes wrong, because cron often is configured to run every 5 minutes. So if something fails on every attempted run, you’ll receive an email every 5 minutes. It is easy to agree that that is annoying.

We’re working on a general solution to resolve the excessive emails issue in a different way. But, until this is changed, cron jobs will behave the Linux server default way. So bear with us 🙂.

When cron mails are sent

Cron will issue an email if there is any output from the cron job. Cron jobs are meant to not produce any output, if everything is ok.

If you start receiving emails, the first thing you should do is to run the cron command that you have received by email – from the command line. You do this by logging in with SSH on the site in question, and then copy and paste the cron string, remove any --quiet parameters and execute it.

The most common reason for these emails

[[email protected] public]$ wp cron event run --due-now --path=/kunder/mlrele_5149/serveb_8061/public/

Success: Executed a total of 0 cron events.

It may be hard to notice in the above example, but between the command and the “Success” line, there is an extra space and an extra line break.

Exactly this issue is the most common thing that triggers these emails. The error is then that a plugin or theme is outputting a space or a line shift that shouldn’t be there. In WordPress, the reason is usually that a developer has added PHP closing tags near the end of the theme functions.php file, or in the wp-config.php file.

...
function somefunction() {
  return TRUE
}
?> 

The above example is wrong, and ends with ?> and some random space afterwards. The correct way to end a PHP file is like following, without the last closing tag and extra space and line shifts:

...
function somefunction() {
  return TRUE
}


Give us your feedback on this article