How to debug WordPress cron
Undisputed leader for WP cron debugging is WP-Crontrol plugin. You can easily see a list of all cron actions scheduled or running now. Also you can simply add new or run existing task.
Sometimes however you may prefer debugging WordPress cron via command line. For example if you don’t want another plugin installed in your website.
How can you debug WP cron with command line? First of all you need wp-cli installed:
1 2 3 4 5 6 7 |
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar $ php wp-cli.phar --info $ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp |
Above commands come from official wp-cli website where you can find up-to-date installation guidelines.
If wp-cli installation went well, you can use it for (among others) cron debugging.
List scheduled cron events:
1 |
wp cron event list |
You will see something like this:
1 2 3 4 5 6 7 8 |
+--------------------------------+---------------------+--------------------+-----------------------+ | hook | next_run_gmt | next_run_relative | recurrence | +--------------------------------+---------------------+--------------------+-----------------------+ | w3_pgcache_cleanup | 2016-08-16 19:16:01 | now | 6 minutes | | w3_pgcache_prime | 2016-08-16 19:17:01 | now | 5 minutes | | w3_objectcache_cleanup | 2016-08-16 19:31:26 | 12 seconds | 16 minutes 40 seconds | | woocommerce_geoip_updater | 2016-09-01 16:30:00 | 2 weeks 1 day | 1 month | +--------------------------------+---------------------+--------------------+-----------------------+ |
You can remove specific cron hook with this command:
1 |
wp cron event delete woocommerce_geoip_updater |
You can also run all events due now with debug flag:
1 |
wp cron event run --due-now --debug |
Sample output:
1 2 3 4 5 6 7 8 9 10 11 12 |
Debug (bootstrap): No readable global config found (0.006s) Debug (bootstrap): No project config found (0.007s) Debug (bootstrap): Loading packages from: /var/www/.wp-cli/packages/vendor/autoload.php (0.103s) Debug (bootstrap): ABSPATH defined: /var/www/ (0.104s) Debug (bootstrap): Begin WordPress load (0.104s) Debug (bootstrap): wp-config.php path: /var/www/wp-config.php (0.104s) Debug (bootstrap): Loaded WordPress (0.334s) Debug (bootstrap): Running command: cron event run (0.334s) Executed the cron event 'w3_pgcache_cleanup' in 0.022s. Executed the cron event 'w3_pgcache_prime' in 2.002s. Executed the cron event 'w3_objectcache_cleanup' in 1.673s. Success: Executed a total of 3 cron events. |
More samples available in official documentation.