I am currently developing application to integrate with shopify, and just tried the SDK from Shopify SDK, then I tried to make a function for get order with paginated request, for example like below
public function getAllOrders(){
// $config is the array that containing accesstoken, password and domain url of shopify store
$shopify = new ShopifySDK($config);
$filters = [
'limit' => 250,
'financial_status' => 'paid',
'fulfillment_status' => 'unfulfilled',
'created_at_min ' => '2020-04-09',
'created_at_max' => '2020-04-10'
];
$orders_resource = $shopify->Order();
$orders = $orders_resource->get($filters);
$next_page = $orders_resource->getNextPageParams();
while ($next_page) {
$next_page_orders = $orders_resource->get($orders_resource->getNextPageParams());
$orders = array_merge($orders, $next_page_orders);
$next_page = $orders_resource->getNextPageParams();
}
return $orders;
}
But it’s give me a memory leaks, instead of being return the response it is give me PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1679360 bytes)
I have reads the advice for setup or tuning the memory limit in php.ini but i thinks it is not good at all, because it’s will force the server to take any size of its request, is there any best practice for something like this or for limit the request page or response data? any advice would be appreciate
2
Answers
I have updated my code, i hope it can helps someone who has same problem like me
That is not the way to do it. Shopify no longer supports paging like that and has told everyone for many months not to do it that way. April 1 was supposed be the end of that pattern. You now get your resource with a call, and then check in the headers if there is more data to get. You use that pattern, clearly described by Shopify. So even if you got this old code going, it is soon to be useless to you. Read up on the new pattern.