Forum archive
Suggested modification to WordPress cron job
Hi, everyone. I recently learned that the cron job that ships with TKL WordPress (and perhaps other appliances) was not working for my sites. I learned this because I kept getting error messages ("You have some tasks that are overdue, etc.") and automatic updates were not being installed. "Surely, this cannot be correct," I thought. "TKL disables wp_cron by default, which makes sense for many reasons, but they use a system cron instead."
All of that is true, but I was wrong. This is the default cron job:
/usr/bin/curl -A 'Mozilla/5.0' 'http://127.0.0.1/wp-cron.php' >/dev/null 2>&1
I went into Webmin and ran it manually, but I received no output. "Eh, that's not good," I thought. I checked my other sites, and they had the same problem.
Fortunately, the following worked for me, which is why I'm sharing it here in case it helps anyone else. You can keep everything the same in terms of the cron frequency, but delete the default cron job and use WP-CLI instead:
/usr/local/bin/wp --path=/var/www/wordpress cron event run --due-now
The above returns output when I run it manually, and I can confirm that it works perfectly on my live sites. Not sure what the deal is with that default cron job, but if you have issues with it, feel free to try the above alternative.
Best regards,
Very Siberian (Rob)
Don't get me wrong, using wp-cli is fine! And I may well follow your lead and replace the default cron job with one that leverages wp-cli.
I wasn't necessarily suggesting that you should change it back to using curl, I was just interested to hear more about it and understand what might be going wrong.
If you do want to get it to work, you can use curl's '--insecure' switch (so it will ignore unmatched certs).
FWIW, the unmatched cert is expected when connecting to localhost (hence why using plain http is the default). Because you can't get a legitimate certificate for 'localhost'!
But as I say, please feel free to continue using the wp-cli cron job that you've implemented.
Also thanks for the clarification re the cron job. I was under the impression that by default it was running as root. Thanks for clarifying that!