Can you just trigger wp-cron.php using for example $ php /path/to/wordpress/wp-cron.php rather than going through the wget method using for example wget -q -O - http://example.com/wp-cron.php>/dev/null 2>&1?

  • Question is: Why would you want/need to do it that way? – leymannx Mar 25 '19 at 20:22
  • 1
    @leymannx for many reasons, maybe your system does not have wget? Cron type of tasks should not require web layer anyway and you should be able to run cron even without the whole site being up. – Tuomas Valtonen Sep 27 '19 at 11:01

Yes, it's possible to trigger cron runs with just $ php /path/to/wordpress/wp-cron.php.

Alternatively you can use curl:

*/10 * * * * curl http://example.com/wp-cron.php > /dev/null 2>&1

And you can add the following line to your wp-config.php to disable crons being run from HTTP requests:

define('DISABLE_WP_CRON', true);
  • If you are using curl that's still an HTTP request so probably not a good idea to DISABLE_WP_CRON? – Bananaapple Jul 10 '20 at 8:20
  • 1
    @Bananaapple – By calling wp-cron.php directly you circumvent that. But at the same time DISABLE_WP_CRON prevents that cron is triggered from visitors browsing any page of your site. See kinsta.com/knowledgebase/disable-wp-cron and in the file comments in my answer above Defining DISABLE_WP_CRON as true and calling this file directly are mutually exclusive and the latter does not rely on the former to work. – leymannx Jul 10 '20 at 8:45

Looking at the file documentation inside wp-cron.php it seems it's absolutely possible to just call $ php wp-cron.php:

 * A pseudo-CRON daemon for scheduling WordPress tasks
 * WP Cron is triggered when the site receives a visit. In the scenario
 * where a site may not receive enough visits to execute scheduled tasks
 * in a timely manner, this file can be called directly or via a server
 * CRON daemon for X number of times.
 * Defining DISABLE_WP_CRON as true and calling this file directly are
 * mutually exclusive and the latter does not rely on the former to work.
 * The HTTP request to this file will not slow down the visitor who happens to
 * visit when the cron job is needed to run.
 * @package WordPress

What else you can do on the command line, is to use wp-cli for that.

$ cd /path/to/wordpress
$ wp cron event run --due-now

To force-trigger one single cron independent from its set schedule run:

$ wp cron event run my_custom_cron_event

Or as a one-liner to be used in a crontab to run every full hour + 15 minutes (2:15 pm, 3:15pm, 4:15pm etc.):

15 * * * * cd /path/to/wordpress && wp cron event run --due-now > /dev/null 2>&1
  • 1
    Is there a benefit to using curl versus the wp cli tool? – Barry Chapman Jan 26 '20 at 6:06
  • 1
    @BarryChapman – Curl basically is just another page request. So it may potentially slow the site down a bit when the cron runs. – leymannx Jan 26 '20 at 15:56
  • @BarryChapman I guess that any code that depends on $_SERVER or other session variables will not like being called from the command line. Other than that you should be fine – alexg Mar 4 at 17:29

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.