Problem with default wp cron job?
every page load its running. high cpu and low performance issues.
The WordPress cron is run by the wp_cron()
function, which is hooked to run on the init
hook, which runs on every page load.
wp_cron()
is defined in wp-includes/cron.php
and hooked in wp-includes/default-filters.php
.
The wp_cron()
function kicks off a wp_remote_post()
request to /wp-cron.php
. Some server configurations prevent scripts sending a request to the same domain like this however, so as an alternative you can set the ALTERNATE_WP_CRON
constant to true
. When enabled this redirects the user to the current URL but with ?doing_wp_cron=
added to the URL, instead of the post request.
What happens if WP-Cron stops working?
WordPress, Themes, and Plugins would never know if a new version is out.
Scheduled posts would never get published, auto drafts never deleted
wp cron job plugins
WP-Cron Schedules
How to Add a Server Cron
root@instance-1:~# crontab -e
no crontab for root – using an empty one
Select an editor. To change later, run ‘select-editor’.
1. /bin/nano <—- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
4. /bin/ed
open cron command
crontab -e
2nd
*/10 * * * * curl https://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
or
*/10 * * * * cd /var/www/example.com; php /var/www/example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
wp rocket nginx github goal serve cached files directly without having to execute any PHP from WordPress
As you may already know, WP-Cron jobs are not real cron jobs and are executed only when you have visits on your site.
disable WordPress cron job,
add the following line to your wp-config.php
: define('DISABLE_WP_CRON', true);
Then, manually a cron job every 15 minutes (it should be enough for most websites):
sudo crontab -e
0 * * * * su daemon -s /bin/sh -c "cd /opt/bitnami/apps/wordpress/htdocs/; /opt/bitnami/php/bin/php -q wp-cron.php"
*/15 * * * * wget -q -O - https://www.website.com/wp-cron.php?doing_wp_cron &>/dev/null
or
*/15 * * * * curl https://www.website.com/wp-cron.php?doing_wp_cron &>/dev/null
or
*/15 * * * * cd /home/user/public_html; php wp-cron.php &>/dev/null
Make sure you test that your tasks still run after this change!
How to Disable WP-Cron (wp-cron.php) & use system cron for Faster Performance
wget -q -O – https://domain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
/dev/null 2>&1 disables email notifications.
https://raazkumar.com/wp-cron.php?doing_wp_cron
*/15 * * * *
cd /var/www/html/raazkumar.com/; php -q wp-cron.php
*/15 * * * * curl https://www.raazkumar.com/wp-cron.php?doing_wp_cron &>/dev/null
disable wp cron nginx
wordpress check if cron is running
root@instance-1:~# */15 * * * * curl https://raazkumar.com/wp-cron.php?doing_wp_cron &>/dev/null
schedule a post If page get published then it means WP Cron is working.
The DISABLE_WP_CRON constant is set to true. WP-Cron spawning is disabled.
open wp-config.php:
remove or comment or set false
define(‘DISABLE_WP_CRON’, true);
define(‘DISABLE_WP_CRON’, true);