Automating WordPress wp-cron on debian

timeSome simple steps to automate the execution of wp-cron.php.

Advantages:

  • You can schedule it at convenient hours without affecting performance for users
  • wp-cron.php become more reliable for almost time-critical tasks (updates, autopost, etc)


2 steps are needed:

  1. Disable the wp-cron execution from wordpress, in the wp-config.php file
  2. Edit your crontab by remote shell

How to disable wp-cron in wp-config.php:
open wp-config.php with your text editor and just add the following line at the end of the file:

define('DISABLE_WP_CRON', true);

Please pay attention in order to avoid blank spaces or newlines at the end of the file, and yes, it is normal that the php closing tag is missing.
Save (and upload if you need to) and here we have done.

How to setup a cronjob for wo-cron in Debian Crontab.
Log into your machine and open the user cronjob typing:

crontab -e

when your crontab will open just paste a line like following adjusting your path to the real one.

*/50 * * * * wget https://blog.giuseppeurso.net/wp-cron.php?doing_wp_cron > /dev/null 2>&1

On this page another approach is proposed and it would be useful for those who want to manage multiple cronjobs at time, but as you probaby already know, one of the advantages coming from using cron is to distribute tasks (the heavyest) in order to not affect (or at least try not affect) the average system performances.
Anyway the solution proposed is to schedule a php file containing the code needed to run the job.

Hope this help
Ciao!
 

(Visited 538 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.