Running wp-cron from CLI

Or, you could use WP-CLI which was developed for scenarios like these. After a short installation like this

$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
$ chmod +x wp-cli.phar
$ sudo mv wp-cli.phar /usr/local/bin/wp

You can run your scheduled tasks like so

$ wp cron event run --due-now --path=/var/www/mywebsite.com/

or via crontab (every 5mins)

*/5 * * * * wp cron event run --due-now --path=/var/www/mywebsite.com/

You could use a specific hook

$ wp cron event run myhook --due-now --path=/var/www/mywebsite.com/

or use the --url parameter.

Leave a Comment