php - 如何在 PHP 中使用 Cronjob 触发 URL?
问题描述
我的主机不支持 CronJob,因此我正在尝试使用 WordPress 内置事件函数wp_schedule_event运行 Cron ,代码似乎正在运行,但是,我正在修改我的代码。我想点击一个 URL 并将响应存储在一个文本文件中,以确保 HIT 已经完成,但我似乎无法弄清楚如何点击一个 URL?
这是代码
// Add a new interval of 180 seconds
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( 'cron_schedules', 'isa_add_every_three_minutes' );
function isa_add_every_three_minutes( $schedules ) {
$schedules['every_three_minutes'] = array(
'interval' => 180,
'display' => __( 'Every 3 Minutes', 'textdomain' )
);
return $schedules;
}
// Schedule an action if it's not already scheduled
if ( ! wp_next_scheduled( 'isa_add_every_three_minutes' ) ) {
wp_schedule_event( time(), 'every_three_minutes', 'isa_add_every_three_minutes' );
}
// Hook into that action that'll fire every three minutes
add_action( 'isa_add_every_three_minutes', 'every_three_minutes_event_func' );
现在在这个函数中,注释代码添加了一个新的 WordPress 帖子,告诉我代码正在运行。但是,当我添加一个 URL 时它没有命中。
function every_three_minutes_event_func() {
// I tried this way but no luck
header('Location: http://example.com');
/* Gather post data.
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
);
// Insert the post into the database.
wp_insert_post( $my_post ); */
}
我必须为此使用 cURL 吗?
请任何指导将不胜感激。非常感谢。
解决方案
推荐阅读
- reactjs - 如何根据 react-admin 中的另一个字段过滤 RadioButton 选项?
- javascript - 在 React 组件悬停时更改背景图像
- c - 如何仅使用指针反转字符串?
- flutter - DraggableScrollableSheet 在拖动时每帧重建所有子项
- stored-procedures - DB2-LUW:存储过程中的 UNION
- javascript - 为什么 1 == 1 == 1,而不是 'A' == 'A' == 'A'
- machine-learning - predict_proba() 函数如何在内部工作?
- node.js - 如何在 cPanel 上安装 etherpad-lite(共享主机)
- javascript - 光滑的滑块代码仅适用于 Android - 为什么它不适用于 iOS(仅限纵向)?
- python - 如何使用 pygame 在 pong 中对弹跳运动进行编码