2

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 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 at 11:01
2

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

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);

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.