我正在编写一个脚本,它应该从我的数据库中结合Wordpress和WooCommmerce返回数组中的两个值。
然而,脚本需要永远加载,所以我要么从cloudflare获得524,要么完成并且什么都不显示。我已将Max执行时间设置为1小时。
是否有任何可以使用我的代码进行优化以实现相同的目的?
<?php
ini_set('display_errors', 'On');
include 'wp-load.php';
function user_balance($user_id){
$args = array(
'customer' => $user_id,
);
$customer_orders = wc_get_orders( $args );
$count = 0;
foreach ( $customer_orders as $customer_order ) :
$order = wc_get_order( $customer_order );
$invs = $order->get_meta( 'type', true, 'view' );
if ( $order->status == "completed" ):
foreach ( $order->get_items() as $item_id => $item_data ) {
$count += $item_data->get_quantity();
}
endif;
endforeach;
return $count;
}
if(current_user_can('administrator')){
$args = array(
'blog_id' => $GLOBALS['blog_id'],
'role' => '',
'role__in' => array(),
'role__not_in' => array(),
'meta_key' => '',
'meta_value' => '',
'meta_compare' => '',
'meta_query' => array(),
'date_query' => array(),
'include' => array(),
'exclude' => array(),
'orderby' => 'login',
'order' => 'ASC',
'offset' => '',
'search' => '',
'number' => '',
'count_total' => false,
'fields' => 'ID',
'who' => '',
);
$userIDs = get_users($args);
foreach($userIDs as $key=>$userID){
$userID = array(
'uid' => $userID,
'balance' => user_balance($userID[$key])
);
}
echo '<pre>'; print_r($userIDs); echo '</pre>';
}
?>