Running wp-cron from CLI

Not sure if my assumption is correct regarding running wp-cron from CLI would be slightly faster than calling it via wget or curl, so either way I’m trying this:

/usr/bin/php /var/www/mywebsite.com/wp-cron.php?import_key=<keyhere>&import_id=1&action=processing

I ensured that path to PHP and the file is correct, but I keep getting this error:

Could not open input file: wp-cron.php?import_key=

What am I doing wrong?

2 Answers
2

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