How to Improve WP Cron Performance
Recently I got some requests from the client who uses my Simple Inventory Sync plugin, and the request was about its “full resync tool”.
The thing is that full resync is using WP Cron to sync product inventory because it is a more seemless solution and sutable for a large stores (with an AJAX approach you can not refresh the tool page and forget about it). But this tool has a limit of HTTP requests per cron job, let’s say 5, so no page overload happen. And even when everything is coded with batch requests, sometimes the client could have tons of products with tons of variations for each for them – in that case the resync will take some time anyway.
The issue is when you have scheduled 1 cron job every minute, but your website has 1 visitor every hour, then guess what – WP Cron will run every hour.
Luckily it is possible to fix if you deactivate WordPress standard cron and just run it from the server.
Let’s do it now.
First things first let’s deactivate the default WordPress Cron in
define( 'DISABLE_WP_CRON', true );
Then I am going to show you how to do it in cPanel, because it is most popular I guess, but I think you could also contact your hosting provider support and they will help you with that.
In cPanel we need “Cron Jobs”.
Let’s just go there.
Now let’s take a closer look at this command:
wget -q -O - https://test.rudrastyh.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
In this command we are sending an HTTP request
wget to a specific URL address quietly
-q sending any output
/dev/null (a virtual device that consumes everything, essentially getting rid of output) and also if any error messages occur
2>&1, send them to