设置 wordpress cron 作业每 2 分钟命中一次 url
Set a wordpress cron job to hit a url every 2 minutes
你好,我有一个 url 可以将数据从 csv 导入 wordpress.I 的数据库,希望每 2 分钟 运行 一次。我尝试了这个 cron job scheduer 的插件,但是这个不工作。
我如何编写动作脚本函数 make this possibe.Please help
您可以执行以下操作
首先,您需要将 2m 间隔添加到时间表
add_filter('cron_schedules', 'my_schedules');
function my_schedules($schedules)
{
$schedules['once_every_2m'] = array('interval' => 120, 'display' => 'Once every 2 minutes');
return $schedules;
}
然后使用新创建的间隔添加作业
if (!wp_next_scheduled('name_of_your_job'))
{
wp_schedule_event(1481799444, 'once_every_2m', 'name_of_your_job');
}
add_action('name_of_your_job', 'function_that_should_be_executed');
function function_that_should_be_executed()
{
//do what you need to do
}
此外,请记住,由于 WP cron 的工作方式,它可能与时间不准确。 Docs
你好,我有一个 url 可以将数据从 csv 导入 wordpress.I 的数据库,希望每 2 分钟 运行 一次。我尝试了这个 cron job scheduer 的插件,但是这个不工作。 我如何编写动作脚本函数 make this possibe.Please help
您可以执行以下操作
首先,您需要将 2m 间隔添加到时间表
add_filter('cron_schedules', 'my_schedules');
function my_schedules($schedules)
{
$schedules['once_every_2m'] = array('interval' => 120, 'display' => 'Once every 2 minutes');
return $schedules;
}
然后使用新创建的间隔添加作业
if (!wp_next_scheduled('name_of_your_job'))
{
wp_schedule_event(1481799444, 'once_every_2m', 'name_of_your_job');
}
add_action('name_of_your_job', 'function_that_should_be_executed');
function function_that_should_be_executed()
{
//do what you need to do
}
此外,请记住,由于 WP cron 的工作方式,它可能与时间不准确。 Docs