From 70ac87df820478a3becca8f2f5e859694c75099f Mon Sep 17 00:00:00 2001 From: 1099511627776 <1099511627776@mail.ru> Date: Tue, 30 Oct 2018 19:29:03 +0200 Subject: [PATCH 1/4] Close connection after stream read --- src/RequestManagers/HttpRequestManager.php | 25 +++++++--------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/RequestManagers/HttpRequestManager.php b/src/RequestManagers/HttpRequestManager.php index 6405321..6a3b527 100644 --- a/src/RequestManagers/HttpRequestManager.php +++ b/src/RequestManagers/HttpRequestManager.php @@ -12,6 +12,7 @@ namespace Web3\RequestManagers; use InvalidArgumentException; +use Psr\Http\Message\StreamInterface; use RuntimeException as RPCException; use Psr\Http\Message\ResponseInterface; use GuzzleHttp\Exception\RequestException; @@ -53,22 +54,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager if (!is_string($payload)) { throw new \InvalidArgumentException('Payload must be string.'); } - // $promise = $this->client->postAsync($this->host, [ - // 'headers' => [ - // 'content-type' => 'application/json' - // ], - // 'body' => $payload - // ]); - // $promise->then( - // function (ResponseInterface $res) use ($callback) { - // var_dump($res->body()); - // call_user_func($callback, null, $res); - // }, - // function (RequestException $err) use ($callback) { - // var_dump($err->getMessage()); - // call_user_func($callback, $err, null); - // } - // ); + try { $res = $this->client->post($this->host, [ 'headers' => [ @@ -78,7 +64,12 @@ class HttpRequestManager extends RequestManager implements IRequestManager 'timeout' => $this->timeout, 'connect_timeout' => $this->timeout ]); - $json = json_decode($res->getBody()); + /** + * @var StreamInterface $result; + */ + $result = $res->getBody(); + $json = json_decode($result); + $result->close(); if (JSON_ERROR_NONE !== json_last_error()) { call_user_func($callback, new InvalidArgumentException('json_decode error: ' . json_last_error_msg()), null); From 54e18048e334e4d72b8e5e4b00f16bf4411752af Mon Sep 17 00:00:00 2001 From: 1099511627776 <1099511627776@mail.ru> Date: Fri, 2 Nov 2018 13:40:24 +0200 Subject: [PATCH 2/4] Rename result to stream --- src/RequestManagers/HttpRequestManager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RequestManagers/HttpRequestManager.php b/src/RequestManagers/HttpRequestManager.php index 6a3b527..0441eeb 100644 --- a/src/RequestManagers/HttpRequestManager.php +++ b/src/RequestManagers/HttpRequestManager.php @@ -65,11 +65,11 @@ class HttpRequestManager extends RequestManager implements IRequestManager 'connect_timeout' => $this->timeout ]); /** - * @var StreamInterface $result; + * @var StreamInterface $stream; */ - $result = $res->getBody(); - $json = json_decode($result); - $result->close(); + $stream = $res->getBody(); + $json = json_decode($stream); + $stream->close(); if (JSON_ERROR_NONE !== json_last_error()) { call_user_func($callback, new InvalidArgumentException('json_decode error: ' . json_last_error_msg()), null); From 29ceef655203a35b102c20422117c71622a1fca8 Mon Sep 17 00:00:00 2001 From: 1099511627776 <1099511627776@mail.ru> Date: Tue, 13 Nov 2018 18:30:21 +0200 Subject: [PATCH 3/4] exclude .idea from tracked files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index efefe03..0aed48d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ composer.phar /vendor/ .phpintel/ +/.idea/ + # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file From b0b1841642f64d77c3c8a91f082ee15c42a31acb Mon Sep 17 00:00:00 2001 From: 1099511627776 <1099511627776@mail.ru> Date: Sun, 13 Jan 2019 12:24:06 +0200 Subject: [PATCH 4/4] Fix indent --- src/RequestManagers/HttpRequestManager.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/RequestManagers/HttpRequestManager.php b/src/RequestManagers/HttpRequestManager.php index 0441eeb..04e0a7d 100644 --- a/src/RequestManagers/HttpRequestManager.php +++ b/src/RequestManagers/HttpRequestManager.php @@ -2,9 +2,9 @@ /** * This file is part of web3.php package. - * + * * (c) Kuan-Cheng,Lai - * + * * @author Peter Lai * @license MIT */ @@ -24,14 +24,14 @@ class HttpRequestManager extends RequestManager implements IRequestManager { /** * client - * + * * @var \GuzzleHttp */ protected $client; /** * construct - * + * * @param string $host * @param int $timeout * @return void @@ -44,7 +44,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager /** * sendPayload - * + * * @param string $payload * @param callable $callback * @return void @@ -64,9 +64,9 @@ class HttpRequestManager extends RequestManager implements IRequestManager 'timeout' => $this->timeout, 'connect_timeout' => $this->timeout ]); - /** - * @var StreamInterface $stream; - */ + /** + * @var StreamInterface $stream ; + */ $stream = $res->getBody(); $json = json_decode($stream); $stream->close();