1. Home
  2. Wordpress
  3. Setting up WordPress cron jobs
  1. Home
  2. Technical
  3. Setting up WordPress cron jobs

Setting up WordPress cron jobs

Contents

By default, WordPress uses a built-in scheduled job execution solution that generates an additional call to the web server each time the page is displayed.

On a high-traffic website, this becomes a problem because it creates an additional delay in displaying the page and uses resources meant to serve the website.

The solution is to disable WordPress from running internal scheduled jobs and set up a system cron in the Crontab option in the web hosting administration:

Add a new cron job. Select System under Execution type and paste the following line in the Command box:

wp cron event run --due-now --path=[[$D2ND_A]]/htdocs/

Scroll down to Scheduling plan  and select after every 5 minutes from schedules.
Then Save changes at the bottom of the page.

Next, a line must be added to the wp-config.php file of the website to disable WP’s built-in cron, e.g. after the database-access setting:

define( 'DISABLE_WP_CRON', true );

How do I check?

You can check /logs/apache.ssl.access.log file to see if WordPress internal cron jobs are stopped.

After changing wp-config.php there should no longer be any references to wp-cron.php:

mydomain.ee 2023-01-28T02:12:24.574229Z 217.146.69.51 38562 - - "POST /wp-cron.php?doing_wp_cron=1674871944.5444300174713134765625 HTTP/1.1"

You can check the performance of the system cron by having the cron send itself email notifications for output and errors. This can be done from the settings of the cron job in question:

After about 5 minutes, the first notification should arrive:

=== Information ===
Result[19950]: Success
Duration Time: 00d 00h 00m 03s
Duration Period: 2023-01-28 13:50:01 - 2023-01-28 13:50:04

=== Command Output (653.0 B) ===
Executed the cron event 'wp_privacy_delete_old_export_files' in 0.002s.
Executed the cron event 'wp_site_health_scheduled_check' in 1.631s.
Executed the cron event 'recovery_mode_clean_expired_keys' in 0.001s.
Executed the cron event 'wp_https_detection' in 0.096s.
Executed the cron event 'wp_version_check' in 0.413s.
Executed the cron event 'wp_update_plugins' in 0.354s.
Executed the cron event 'wp_update_themes' in 0.352s.
Executed the cron event 'wp_scheduled_delete' in 0.004s.
Executed the cron event 'delete_expired_transients' in 0.002s.
Executed the cron event 'wp_update_user_counts' in 0.001s.
Success: Executed a total of 10 cron events.

You can then turn off the notification or choose to be notified only in case of errors.

Updated on 19. Aug 2024
Was this article helpful?

Related Articles