问题描述
我有一个有3,000种产品的wordpress-Woocommerce网站。 我想每天运行一次代码。
问题-我不希望它每天一次运行3,000种产品, 我希望它每天运行一次,但是要排队,每分钟10个产品,这样服务器就不会掉下来。
我的代码现在运行良好,每分钟10个产品的运行循环:
$args= array(
'post_type' => 'product','posts_per_page' => 10,'Meta_query' => array(
array(
'key' => 'ob_url','compare' => 'NOT EXISTS'
),),);
现在,我想了解如何使此代码每分钟运行10个产品-每天执行一次:开始每天运行一次,直到完成所有产品的运行,但间隔相同每分钟10种产品。
add_action( 'wp','prefix_setup_schedule' );
/**
* On an early action hook,check if the hook is scheduled - if not,schedule it.
*/
function prefix_setup_schedule() {
if ( ! wp_next_scheduled( 'prefix_daily_event' ) ) {
wp_schedule_event( time(),'daily','prefix_daily_event');
}
}
add_action( 'prefix_daily_event','prefix_do_this_daily' );
/**
* On the scheduled action hook,run a function.
*/
function prefix_do_this_daily() {
// updating some custom Meta per product.
}
也许解决方案是在时间表内制定时间表: 任务1:每天一次-任务2:以1分钟的间隔安排。 但是..我找不到正确的书写方式,如何保证1分钟的任务不会永远运行。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)