slince / shopify-api-php

:rocket: Shopify API Client for PHP
MIT License
128 stars 48 forks source link

Delay next request not works #2

Closed maximzasorin closed 6 years ago

maximzasorin commented 6 years ago

Hello, your lib is awesome, but the delay before the next request in sendRequest looks useless. I create and run next code for example:

$client = ...;

$shopManager = $client->getShopManager();
$index = 1;

while (true) {
    print ($index++) . ' ' . $shopManager->get()->getName() . "\n";
}

And it throws 429 Too Many Requests exception after ~57 requests.

slince commented 6 years ago

Hi, i have tested 176 requests and have not yet finished; Can you tell me what kind of credentials you are using, public or private?

157 SNSELL
158 SNSELL
159 SNSELL
160 SNSELL
161 SNSELL
162 SNSELL
163 SNSELL
164 SNSELL
165 SNSELL
166 SNSELL
167 SNSELL
168 SNSELL
169 SNSELL
170 SNSELL
171 SNSELL
172 SNSELL
173 SNSELL
174 SNSELL
175 SNSELL
176 SNSELL
^C

maximzasorin commented 6 years ago

I using public credentials. On my local machine I can not get problem, but on my DO droplet it occurs stable on 50–70 requests. Should the solution in sendRequest work correctly with call limit from docs?

slince commented 6 years ago

Maybe the pause time is too short; can you modify sleep time in your vendor and try again? https://github.com/slince/shopify-api-php/blob/master/src/Client.php#L305

For example:

  usleep(1000000 * rand(3, 10));
maximzasorin commented 6 years ago

I modify sleep to:

usleep(1000000 * rand(3, 10));

And it works correctly on more than 500 requests.

maximzasorin commented 6 years ago

@slince Will this fix be added to the release?

slince commented 6 years ago

of course. give me some time. 😈