Trigger WP-Cron with a cronjob on a WordPress site with ISPConfig

Procédure

What is WP-Cron?

WP-Cron is the internal WordPress mechanism that imitates the Linux cron service to run scheduled tasks in the background on WordPress. Among other things, this enables automatic updates, cache warm-ups and WooCommerce maintenance tasks to be carried out. Since plugins have access to this mechanism, they can add tasks to be executed in order to schedule additional actions. You can find out more in our dedicated blog post: What is WordPress CRON?

Why trigger WP-Cron with a cronjob?

WP-Cron was originally designed to replace cronjob on web hosting packages that don't allow you to add a script to the Linux cron service. As a result, WP-Cron triggers the execution of tasks thanks to requests made to the wp-cron.php file, during AJAX requests made to wp-admin/admin-ajax.php, and/or when the page is loaded. So the trigger for these HTTP requests is inevitably the visit to the website. As a result, page loading will be encumbered by the execution of WP-Cron tasks and performance may be reduced. Worse still, some plugins add tasks that are far too long on Wp-Cron, to the point of exceeding the possible HTTP waiting times. And most disturbingly, the execution of tasks could be delayed because there are no visitors on the site at the time when the task should have been executed. Some tasks could therefore accumulate, and when a visitor opens the page, dozens or even hundreds of scheduled tasks could be dropped, greatly penalising loading time for this unfortunate visitor.

Triggering WP-Cron with a cron job therefore ensures that tasks scheduled with WP-Cron are executed without affecting visitors: wp-cron.php will then be executed at regular intervals, whether or not there are visitors, and visitors can immediately open the site without waiting for pending tasks to be executed.

Step 1: Disable WP-Cron from executing when a page is loaded

First of all, you need to disable WP-Cron from running when a page is loaded. This is done by adding the following line to your wp-config.php file:

define( 'DISABLE_WP_CRON', true );

To do this, go to your FTP client, connect to your FTP account and edit the wp-config.php file:

Trigger WP-Cron with a cronjob on a WordPress site with ISPConfig

Step 2: Trigger wp-cron.php from a cron job

In your ISPConfig control panel, go to Sites > Cron jobs and click on"New cron":

Trigger WP-Cron with a cronjob on a WordPress site with ISPConfig

Then enter a cronjob that runs every minute and executes the wp-cron.php file:

Trigger WP-Cron with a cronjob on a WordPress site with ISPConfig

The command to be executed,"php7.4 [web_root]/wp-cron.php" can be adjusted:

  • php7.4 indicates the PHP binary to be used. If your website uses another version, be sure to adjust the version indicated.
  • [web_root] represents the "web" folder in your FTP. You should also adjust this if your WordPress site is located in a particular directory.

The "Log output" checkbox allows you to log the output of wp-cron in the "private" folder of your FTP account. You can check it if you want to have the stdout and stderr output of wp-cron.php, useful for debugging, for example.

You can find out more aboutscheduled cron job tasks on your VPS in the dedicated article.

A few pitfalls to avoid

By default, sites created on ISPConfig are not associated with any customer account:

Trigger WP-Cron with a cronjob on a WordPress site with ISPConfig

However, if you have voluntarily associated your website with a customer or reseller account created on ISPConfig, then this account may have certain cron limits that could prevent the cron job from working properly. To check these limits, go to the Limits tab of the customer/reseller account:

Trigger WP-Cron with a cronjob on a WordPress site with ISPConfig

Make sure you have chosen Full cron so that the cronjob doesn't run in a limited jail chroot that doesn't have all the functions needed for the cronjob to work properly:

Trigger WP-Cron with a cronjob on a WordPress site with ISPConfig

Also make sure you set the minimum time between runs to "1" so that the cronjob can run every minute.

If you have already created cronjobs and/or shell users for the site, it will be necessary to delete all the existing cronjobs and shell users, and then recreate them, so that ISPConfig can switch them from a chroot environment to a full cron environment.

Rate this article :

5/5 | 2 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

0mn reading

How do you disable mod_security on a website on your VPS using the ISPConfig panel?

1mn reading

Bandwidth limits on VPS servers

2mn reading

How to configure two-factor authentication on ISPConfig


Ask the LWS team and its community a question