Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-php): honour long timeouts on Guzzle 8 streams
Yudhi Armyndharisa6eb787052c0
diff --git a/sdk/php/src/Http/HttpExecutor.php b/sdk/php/src/Http/HttpExecutor.phpindex 21c6bf7a7..aea208508 100644--- a/sdk/php/src/Http/HttpExecutor.php+++ b/sdk/php/src/Http/HttpExecutor.php@@ -242,6 +242,12 @@ class HttpExecutor'Accept' => 'application/json',]),];+ // Guzzle 8's stream handler also stops a connection that stays silent for 60 s (read_timeout, 0 disables+ // it), which would cut off a longer timeout or none. Guzzle 7 reads the option differently (0 and+ // fractions end reads at once), so only 8 is told; cURL handlers ignore it.+ if (ClientInterface::MAJOR_VERSION >= 8) {+ $options['read_timeout'] = $this->timeout;+ }if ($idempotencyKey !== null) {$options['headers']['Idempotency-Key'] = $idempotencyKey;}diff --git a/sdk/php/tests/ClientTest.php b/sdk/php/tests/ClientTest.phpindex 8322f2aab..8a1379f70 100644--- a/sdk/php/tests/ClientTest.php+++ b/sdk/php/tests/ClientTest.php@@ -544,6 +544,31 @@ class ClientTest extends TestCasereturn $cases;}+ public function testTheTimeoutIsAlsoTheIdleReadTimeoutOnGuzzle8Only(): void+ {+ // Guzzle 8's stream handler (a host without ext-curl) also stops a connection that stays silent for+ // 60 s unless read_timeout says otherwise, which would cut off a longer timeout, and 0 means no bound.+ // Guzzle 7 reads the option differently (0 and fractions end reads at once), so it is left out there.+ foreach ([100.0, 1.25, 0.0] as $timeout) {+ $mock = new \GuzzleHttp\Handler\MockHandler([new \GuzzleHttp\Psr7\Response(200)]);+ $client = new \OpenWA\Client([+ 'baseUrl' => 'http://localhost:2785',+ 'apiKey' => 'k',+ 'timeout' => $timeout,+ 'httpClient' => new \GuzzleHttp\Client(['handler' => \GuzzleHttp\HandlerStack::create($mock)]),+ ]);+ $client->request('GET', '/api/anything');+ $options = $mock->getLastOptions();++ $this->assertSame($timeout, $options['timeout']);+ if (\GuzzleHttp\ClientInterface::MAJOR_VERSION >= 8) {+ $this->assertSame($timeout, $options['read_timeout'] ?? null);+ } else {+ $this->assertArrayNotHasKey('read_timeout', $options);+ }+ }+ }+public function testTimedOutMessageWithoutErrnoMapsToTimeoutException(): void{// Transports that leave the handler context empty (e.g. the stream handler)