最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Triggering cron by calling wp-cron.php on the command line rather than with wget?

programmeradmin1浏览0评论

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 - .php>/dev/null 2>&1?

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/wp-cron.php>/dev/null 2>&1?

Share Improve this question edited Mar 25, 2019 at 21:58 norman.lol 3,2413 gold badges30 silver badges35 bronze badges asked Aug 26, 2015 at 7:16 ScottScott 911 gold badge1 silver badge2 bronze badges 2
  • Question is: Why would you want/need to do it that way? – norman.lol Commented Mar 25, 2019 at 20:22
  • 2 @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 Commented Sep 27, 2019 at 11:01
Add a comment  | 

2 Answers 2

Reset to default 10

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

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/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);
发布评论

评论列表(0)

  1. 暂无评论