wp cron - Why would wp_schedule_single_event get delayed start?

I'm using wp_schedule_single_event to run a function in the background immediately when a logged in user visits the

I'm using wp_schedule_single_event to run a function in the background immediately when a logged in user visits the dashboard page. The problem I'm having is that the time between triggering and the function actually running varies between a few seconds and 5 minutes.

I'm debugging by emailing myself as soon as I call wp_schedule_single_event, and then in the function that is called. I know the event is scheduled immediately because I get the email quickly, _transient_doing_cron is created in the wp_options table, and the name of my action is added to cron in wp_options while it needs to be run.

My function runs fairly quickly and is done in less than 10 seconds. It's as if wordpress is running other crons before it, but I've tested this multiple times only a few minutes apart, so I can't always be getting an hourly cron that needs to be run. Can I prioritize my event to be run first? What else could be happening?

I'm using wp_schedule_single_event to run a function in the background immediately when a logged in user visits the dashboard page. The problem I'm having is that the time between triggering and the function actually running varies between a few seconds and 5 minutes.

I'm debugging by emailing myself as soon as I call wp_schedule_single_event, and then in the function that is called. I know the event is scheduled immediately because I get the email quickly, _transient_doing_cron is created in the wp_options table, and the name of my action is added to cron in wp_options while it needs to be run.

My function runs fairly quickly and is done in less than 10 seconds. It's as if wordpress is running other crons before it, but I've tested this multiple times only a few minutes apart, so I can't always be getting an hourly cron that needs to be run. Can I prioritize my event to be run first? What else could be happening?

Share Improve this question asked Apr 19, 2019 at 20:52 Patrick St.OngePatrick St.Onge 211 bronze badge 1
  • Hi, welcome to WPSE. It'll be helpful if you provide the actual CODE involving the calling and implementation of wp_schedule_single_event. So it's better if you edit your question and provide the CODE. – Fayaz Commented Apr 20, 2019 at 6:39
Add a comment  | 

1 Answer 1

Reset to default 2

Cron execution may differ depending on when the system cron is actually being run. For example, if your system is running cron at 5 minutes interval, even a cron scheduled for immediate run will execute between a few seconds to 5 minutes.

You may use the WP Crontrol Plugin to check the cron schedules set by WordPress in case other cron tasks are affecting it. To check system cron schedules, use crontab command or check cron settings from CPanel.

Also, if you don't have define('DISABLE_WP_CRON', true); set in wp-config.php, and there is no Operating System cron running, that means WordPress is running the crons. In that case cron event execution will depend on site visits. However, from your following description:

the function actually running varies between a few seconds and 5 minutes.

it looks like an Operating System cron is running at 5 minutes interval. You may make it one minute interval to get faster execution.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745570337a4633642.html

相关推荐

  • wp cron - Why would wp_schedule_single_event get delayed start?

    I'm using wp_schedule_single_event to run a function in the background immediately when a logged in user visits the

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信