Reputation: 350
I am trying to fetch all the products of a Shopify store in my app using the Shopify API. I have the following code to fetch all the products page-wise. This script is breaking at some point in time, but I am not sure where. How can I make a thorough script which will fetch all the products in one go without breaking.
Here is what I have thus far:
$ch = curl_init();
for ($i=1; $i<=1000; $i++)
{
curl_setopt($ch, CURLOPT_URL, "https://API:PASS@store/products.json?page=$i");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
$res = curl_exec($ch);
$res=json_decode($res, true);
foreach($res as $products) { // A different example
foreach($products as $product) {
$title=$product['title'];
}
}
sleep(1);
}
curl_close($ch);
Upvotes: 3
Views: 3325
Reputation: 2766
You're probably reaching the Shopify API limit call. So you'd probably need to work with queues. Here is how the Shopify API limit calculations work:
Shopify uses a leaky bucket algorithm with a bucket size of 40 calls, and a leak rate of 2 per second.
How does that work:
What does that mean for your app:
Upvotes: 5