通过在命令行调用wp-cron.php而不是使用wget触发cron?

时间:2015-08-26 作者:Scott

你能触发吗wp-cron.php 例如使用$ php /path/to/wordpress/wp-cron.php 而不是使用wget方法,例如wget -q -O - http://example.com/wp-cron.php>/dev/null 2>&1?

2 个回复
SO网友:leymannx

查看内部的文件文档wp-cron.php 看来完全可以打电话$ 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
 */
您还可以在命令行上执行以下操作wp-cli 为此。

$ cd /path/to/wordpress
$ wp cron event run --due-now
要强制触发一个独立于其设置的计划运行的cron,请执行以下操作:

$ wp cron event run my_custom_cron_event
或者作为一个用于crontab的一行程序,每小时+15分钟运行一次(下午2:15、下午3:15、下午4:15等):

15 * * * * cd /path/to/wordpress && wp cron event run --due-now > /dev/null 2>&1

SO网友:Mat

是的,可以触发cron运行,只需$ php /path/to/wordpress/wp-cron.php.

或者,您可以使用curl:

*/10 * * * * curl http://example.com/wp-cron.php > /dev/null 2>&1
您可以将以下行添加到wp-config.php 要禁用从HTTP请求运行的cron,请执行以下操作:

define(\'DISABLE_WP_CRON\', true);