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

WP Cron scheduling doesn't work reliably on hosted server

programmeradmin0浏览0评论

The following code is part of a save_post action. It works as expected in my local dev environment, but doesn't work reliably on a hosted server. (By unreliably I mean it sometimes work, but without any regularity I can deduce.)

if (wp_next_scheduled('my_expiration_hook', [$post_id])) {
    my_log('unscheduling all for post ' . $post_id);
    wp_clear_scheduled_hook('my_expiration_hook', [$post_id]);
}

if ($today < $expire) {
    my_log('scheduling ' . $post_id . ' with date ' . $expire);
    wp_schedule_single_event(strtotime($expire), 'my_expiration_hook', [$post_id]);
}

Everything logs correctly, but it is as if the wp_clear_scheduled_hook and wp_schedule_single_event calls never occur.

I am using WP Crontrol plugin to check the schedule. Manually modifying the schedule with this plugin works as expected.

Am I missing something or is this a hosting issue? Thanks!

The following code is part of a save_post action. It works as expected in my local dev environment, but doesn't work reliably on a hosted server. (By unreliably I mean it sometimes work, but without any regularity I can deduce.)

if (wp_next_scheduled('my_expiration_hook', [$post_id])) {
    my_log('unscheduling all for post ' . $post_id);
    wp_clear_scheduled_hook('my_expiration_hook', [$post_id]);
}

if ($today < $expire) {
    my_log('scheduling ' . $post_id . ' with date ' . $expire);
    wp_schedule_single_event(strtotime($expire), 'my_expiration_hook', [$post_id]);
}

Everything logs correctly, but it is as if the wp_clear_scheduled_hook and wp_schedule_single_event calls never occur.

I am using WP Crontrol plugin to check the schedule. Manually modifying the schedule with this plugin works as expected.

Am I missing something or is this a hosting issue? Thanks!

Share Improve this question edited Jan 26, 2022 at 21:09 noos asked Jan 26, 2022 at 21:02 noosnoos 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

Most hosts modify how the default cron works and I've specifically had issues with GoDaddy managed hosting as they 100% take control and you can't do anything about it.

If it works locally, I would contact the hosting company and ask about how crons are setup to run. If its Managed GoDaddy there isn't anything you can do but to change hosts. I fought them for 3 months before the client finally agreed.

Another thing to look out for is object caching, I've seen it cause some issues as well.

发布评论

评论列表(0)

  1. 暂无评论