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
https://wordpress.org/plugins/wp-crontrol/
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);
How to Create a Cron Job and Execute at a Given Time
1 22-5 * * *
1st minute every 22nd hour to 5 hours 10PM – to 5AM run at low peak time of website traffic.
MIN HOUR Day of month Month Day of Week Command 0-59 0-23 1-31 1-12 0-6 linux command or script
40 18 20 04 * /home/backups/full-backup
Explanation
40 – 40th Minute 18 – 06 PM 20 – 20th Day 04 – 4th Month (April) * – Every day of the week
once a day 00AM
0 0 * * *
disable wordpress cron server level at nginx
add in default server or specific server location of a website.
location = /xmlrpc.php {
deny all;
internal;
access_log /dev/null;
log_not_found off;
}
location /wp-cron.php { deny all; internal;
access_log /dev/null;
log_not_found off; }