admin管理员组文章数量:1418590
I'm trying to add a cron job to run file daily at 7pm.
How can i add the file run command and specify to run it at 7pm ?
// Scheduled Action Hook
function run_my_script( ) {
// run my file : mysite/cron.php
}
// Schedule Cron Job Event
function USERS_MONITORING() {
if ( ! wp_next_scheduled( 'USERS_MONITORING' ) ) {
wp_schedule_event( time(), 'daily', 'USERS_MONITORING' );
}
}
add_action( 'wp', 'USERS_MONITORING' );
I don't know if there is a better solution.
I'm trying to add a cron job to run file daily at 7pm.
How can i add the file run command and specify to run it at 7pm ?
// Scheduled Action Hook
function run_my_script( ) {
// run my file : mysite/cron.php
}
// Schedule Cron Job Event
function USERS_MONITORING() {
if ( ! wp_next_scheduled( 'USERS_MONITORING' ) ) {
wp_schedule_event( time(), 'daily', 'USERS_MONITORING' );
}
}
add_action( 'wp', 'USERS_MONITORING' );
I don't know if there is a better solution.
Share Improve this question edited Aug 9, 2017 at 10:13 octavelhiver asked Aug 9, 2017 at 9:17 octavelhiveroctavelhiver 231 silver badge4 bronze badges 4 |1 Answer
Reset to default 2You can include the PHP file and do the tasks, if WP-cron is your only option.
// Scheduled Action Hook
function run_my_script( ) {
require_once('related/path/to/php/file.php');
}
// Schedule Cron Job Event
function USERS_MONITORING() {
if ( ! wp_next_scheduled( 'USERS_MONITORING' ) ) {
wp_schedule_event( strtotime('07:00:00'), 'daily', 'USERS_MONITORING' );
}
}
add_action( 'USERS_MONITORING', 'run_my_script' );
Note that you need to include the related path. If you want to access the PHP file by its URL, you need to use cURL instead.
Also, as @rarst mentioned in one of his posts:
Note : WP Cron isn't guaranteed to run at precise time since it is trigerred by visits to the site. I am not confident if recurrent runs will "stick" at midnight or will slowly slip from there, you might need to readjust periodically.
本文标签: wp cronRun a php file daily at specific time
版权声明:本文标题:wp cron - Run a php file daily at specific time 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745297314a2652159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
cron.php
, for security reasons. I could hit that file repeatedly to cause a denial of service attack via resource exhaustion – Tom J Nowell ♦ Commented Aug 9, 2017 at 9:56