WP-Cron and GridPane’s GP-Cron

2 min read

WP-Cron is how WordPress handles scheduling time-based tasks such as checking for updates and publishing scheduled post.

At GridPane, we have GPCron, which does the same thing, but at the server level. Unlike WP-Cron, which relies on people visiting your website, you can set it to run at specific time intervals, which assures that things like scheduled posts won’t miss being published.

Using GPCron

The following will setup gpcron to run on your website (it is not on by default). WP cron is disabled and set as a server cronjob with this command:

gp site {site.url} -gpcron-on {minute.interval}

{site.url} is your site.

{minute.interval} is an integer value for minutes, it can be set from 1 to 60 minutes.

The cron will run as a system user cron for your site’s PHP user.

For Example:

gp site gridpane.com -gpcron-on 15

The above sets GPCron to run every 15 minutes on gridpane.com

Note

Below shows how to check your cronjob, however, if you need to wish to run any GP-CLI afterwards you will need to logout of (exit) the system user with:

exit

Checking your cronjob

These Cron jobs do not run under the root cron, as this would elevate WP PHP processes to root privilege and create a security risk, so you won’t find these in the regular crontab. You will need to check the website’s system user-specific crontab.

To do that you need to first move into your websites system user and display the crontab:

sudo su - {system.user}
crontab -l

{system.user} is the system user your site belongs to.

For example:

sudo su - steveswebs8348

You can also check running just one singular command as follows:

sudo su - {system.user} -c "crontab -l"

If you have run the command correctly, say for 1 minute, you should see the following in your users crontab:

*/1 * * * * wget -q -O - http://{your.site}/wp-cron.php?doing_wp_cron >/dev/null 2>&1

For more information on WP-Cron, you can check out the official documenation here:

https://developer.wordpress.org/plugins/cron/