derdd1199
derdd1199

Reputation: 13

PHP - Multiple Api Call - Response time more then 15 seconds?

I need to get the order count for the last 30 days in a 1 day period. That´s what I wrote but the response time is 15 seconds and up. Is there any smarter strategy, maybe a Simultaneous asynchronous API call? I did not found a direct call to the orders api to receive the daily orders with one request. Any one any ideas?

Here´s my code:

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);

}

Upvotes: 1

Views: 309

Answers (1)

ankit singh
ankit singh

Reputation: 575

Hello as per your code you are calling shopify Api in a loop that's why it is taking time . So you can fetch last 30 days order first and after that you can easily distinguish order by order created date.

You can take reference by this api doc Shopify order Api

In this doc you can fetch last 30 days order by created_at_min filter

Upvotes: 1

Related Questions