diff --git a/CHANGELOG.md b/CHANGELOG.md index 05acb39..81b8568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.2.4 + +* [Fixed] set timeout in client + ## 7.2.3 * [Fixed] Include socket_id in batch trigger if included. diff --git a/src/Pusher.php b/src/Pusher.php index 29979dd..d036a0b 100755 --- a/src/Pusher.php +++ b/src/Pusher.php @@ -64,12 +64,6 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar { $this->check_compatibility(); - if (!is_null($client)) { - $this->client = $client; - } else { - $this->client = new \GuzzleHttp\Client(); - } - $useTLS = true; if (isset($options['useTLS'])) { $useTLS = $options['useTLS'] === true; @@ -119,6 +113,13 @@ public function __construct(string $auth_key, string $secret, string $app_id, ar ); $this->crypto = new PusherCrypto($parsedKey); } + + + if (!is_null($client)) { + $this->client = $client; + } else { + $this->client = new \GuzzleHttp\Client(['timeout' => $this->settings['timeout'],]); + } } /** @@ -724,7 +725,8 @@ public function get(string $path, array $params = [], $associative = false) 'query' => $signature, 'http_errors' => false, 'headers' => $headers, - 'base_uri' => $this->channels_url_prefix() + 'base_uri' => $this->channels_url_prefix(), + 'timeout' => $this->settings['timeout'] ]); $status = $response->getStatusCode(); @@ -776,7 +778,8 @@ public function post(string $path, $body, array $params = []) 'body' => $body, 'http_errors' => false, 'headers' => $headers, - 'base_uri' => $this->channels_url_prefix() + 'base_uri' => $this->channels_url_prefix(), + 'timeout' => $this->settings['timeout'] ]); } catch (ConnectException $e) { throw new ApiErrorException($e->getMessage()); @@ -826,7 +829,8 @@ public function postAsync(string $path, $body, array $params = []): PromiseInter 'body' => $body, 'http_errors' => false, 'headers' => $headers, - 'base_uri' => $this->channels_url_prefix() + 'base_uri' => $this->channels_url_prefix(), + 'timeout' => $this->settings['timeout'], ])->then(function ($response) { $status = $response->getStatusCode(); diff --git a/tests/unit/PusherConstructorTest.php b/tests/unit/PusherConstructorTest.php index e1efcde..f7acdf8 100644 --- a/tests/unit/PusherConstructorTest.php +++ b/tests/unit/PusherConstructorTest.php @@ -22,8 +22,8 @@ public function testUseTLSOptionWillBeOverwrittenByHostAndPortOptionsSetHostAndP { $options = [ 'useTLS' => true, - 'host' => 'test.com', - 'port' => '3000', + 'host' => 'test.com', + 'port' => '3000', ]; $pusher = new Pusher('app_key', 'app_secret', 'app_id', $options); @@ -60,11 +60,22 @@ public function testClusterOptionIsOverriddenByHostIfItExists(): void { $options = [ 'cluster' => 'eu', - 'host' => 'api.staging.pusher.com', + 'host' => 'api.staging.pusher.com', ]; $pusher = new Pusher('app_key', 'app_secret', 'app_id', $options); $settings = $pusher->getSettings(); self::assertEquals('api.staging.pusher.com', $settings['host']); } + + public function testSetTimeoutOption(): void + { + $options = [ + 'timeout' => 10, + ]; + $pusher = new Pusher('app_key', 'app_secret', 'app_id', $options); + + $settings = $pusher->getSettings(); + self::assertEquals(10, $settings['timeout']); + } }