admin管理员组文章数量:1026989
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 |1 Answer
Reset to default 2Cron 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.
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
1 Answer
Reset to default 2Cron 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.
本文标签: wp cronWhy would wpschedulesingleevent get delayed start
版权声明:本文标题:wp cron - Why would wp_schedule_single_event get delayed start? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745570335a2156697.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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