【发布时间】:2020-01-12 19:07:48
【问题描述】:
我需要获取 1 天内过去 30 天的订单数。这就是我写的,但响应时间是 15 秒以上。有没有更聪明的策略,也许是同时异步 API 调用?我没有找到直接调用 orders api 来接收一个请求的每日订单。有人有什么想法吗?
这是我的代码:
for ($i = 0; $i < 30; $i++)
{
$timestamp = time();
$tm = 86400 * $i; // 60 * 60 * 24 = 86400 = 1 day in seconds
$tm = $timestamp - $tm;
$the_date = date("Y-m-d", $tm);
$newdate = date('Y-m-d', strtotime($the_date. ' + 1 days'));
$orderinfo = shopify_call($token, $shop, "/admin/orders/count.json?status=any&created_at_min=".$the_date."&created_at_max=".$newdate, $array, 'GET');
$orderinfo = json_decode($orderinfo['response'], JSON_PRETTY_PRINT);
print_r($orderinfo);
}
【问题讨论】:
-
要进行异步调用,您需要找到支持承诺的库或使用 guzzle http 客户端之类的东西编写自己的调用。