diff --git a/src/Transporter/GuzzleHttpTransporter.php b/src/Transporter/GuzzleHttpTransporter.php index 509f541..57af769 100644 --- a/src/Transporter/GuzzleHttpTransporter.php +++ b/src/Transporter/GuzzleHttpTransporter.php @@ -35,8 +35,8 @@ class GuzzleHttpTransporter extends AbstractTransporter public function __construct(string $host = '', int $port = 9501, array $config = []) { - $this->host = $host; - $this->port = $port; + parent::__construct($host, $port); + $this->config = array_merge_recursive($config, [ 'headers' => [ 'Content-Type' => 'application/json', diff --git a/src/Transporter/StreamSocketTransporter.php b/src/Transporter/StreamSocketTransporter.php index 396962f..b9a0f51 100644 --- a/src/Transporter/StreamSocketTransporter.php +++ b/src/Transporter/StreamSocketTransporter.php @@ -24,11 +24,6 @@ class StreamSocketTransporter extends AbstractTransporter */ protected $client; - /** - * @var int - */ - protected $timeout; - /** * @var bool */ @@ -69,19 +64,19 @@ public function recv() public function receive() { $buf = ''; - $timeout = 1000; + $timeoutMs = $this->timeout > 0 ? $this->timeout * 1000 : 1000; stream_set_blocking($this->client, false); // The maximum number of retries is 12, and 1000 microseconds is the minimum waiting time. // The waiting time is doubled each time until the server writes data to the buffer. // Usually, the data can be obtained within 1 microsecond. - $result = retry(12, function () use (&$buf, &$timeout) { + $result = retry(12, function () use (&$buf, &$timeoutMs) { $read = [$this->client]; $write = null; $except = null; - while (stream_select($read, $write, $except, 0, $timeout)) { + while (stream_select($read, $write, $except, 0, $timeoutMs)) { foreach ($read as $r) { $res = fread($r, 8192); if (feof($r)) { @@ -92,7 +87,7 @@ public function receive() } if (! $buf) { - $timeout *= 2; + $timeoutMs *= 2; throw new RecvFailedException('No data was received'); }