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.


the CLI PHP interpreter is not exactly the same as the one invoke by the webserver. A lot of enviroment information you expect the webserver to pass will not exist in the CLI, and the CLI is not assuming that its input is a URL.

Since in CLI there is no special meaning to ? but there is to &, the shell enviroment passes to php /var/www/mywebsite.com/wp-cron.php?import_key as a parameter which should incicate which file to run.

Instead, you should use wget to invoke the operation via the web server, in a proper web enviroment wget mywebsite.com/wp-cron.php?import_key=<keyhere>&import_id=1&action=processing

Side note: In theory you should not not need to pass parameters to cron, and then you can do /usr/bin/php /var/www/mywebsite.com/wp-cron.php

  • So you're saying I could just run /usr/bin/php /var/www/mywebsite.com/wp-cron.php without the query string? But how would it know which import_id and action?
    – Nimbuz
    Aug 26, 2017 at 4:27
  • the cron works by inspecting its event queue and "running" the events that need to be run. It do not require any external parameter for that. Not sure why you think you need to pass that parameter Aug 26, 2017 at 4:32
  • Oh ok, I was under the impression that query parameters is required because thats what the plugin mentions: It processes in iteration (only importing a few records each time it runs) to optimize server load. It is recommended you run the execution script every 2 minutes.
    – Nimbuz
    Aug 26, 2017 at 4:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.