Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit cbe906f

Browse files
committed
add automatic resend request
1 parent 6036874 commit cbe906f

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# (English) Wildberries REST API statistics client library with throttling requests
22
## Русское описание ниже, после английского
33

4-
A simple Wildberries REST API statistics client library with throttling requests (for example, no more than 10 requests per second according to API rules) and an example for PHP.
4+
A simple Wildberries REST API statistics client library with throttling requests (for example, no more than 10 requests per second according to API rules) and an example for PHP. Automatic request resending is supported when the http response code "429: too many requests" is received.
55

66
Statistics API Documentation [Wildberries REST API statistics Documentation](https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf)
77

@@ -84,7 +84,7 @@ $incomes = $WbApiClient->incomes();
8484

8585
# (Russian) Клиентская REST API библиотека статистики Wildberries с регулированием запросов
8686

87-
Простая клиентская REST API библиотека статистики Wildberries с регулированием запросов (например, не более 10 запросов в секунду в соответствии с правилами API) и примером для PHP.
87+
Простая клиентская REST API библиотека статистики Wildberries с регулированием запросов (например, не более 10 запросов в секунду в соответствии с правилами API) и примером для PHP. Поддерживается автоматическая повторная отправка запроса при получении http кода ответа "429: too many requests".
8888

8989
Описание API статистики [Wildberries REST API statistics](https://images.wbstatic.net/portal/education/Kak_rabotat'_s_servisom_statistiki.pdf)
9090

src/WbApiClient.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,16 @@ private function throttleCurl()
311311
usleep( $usleep );
312312
} while ( false );
313313

314-
$this->lastRequestTime = microtime( true );
314+
do {
315+
$this->lastRequestTime = microtime( true );
316+
$response = curl_exec( $this->curl );
315317

316-
$response = curl_exec( $this->curl );
318+
$oneMoreTry = curl_getinfo( $this->curl, CURLINFO_RESPONSE_CODE ) == 429;
319+
if ( $oneMoreTry ) {
320+
$this->debug( "[{$this->requestCounter}] +++++ TOO MANY REQUESTS, WAITING 0.5sec +++++", self::DEBUG_URL );
321+
usleep( 500000 );
322+
}
323+
} while ( $oneMoreTry );
317324

318325
return $response;
319326
}

0 commit comments

Comments
 (0)