Merge pull request #135 from 1099511627776/bclounge

Close connection after stream read
This commit is contained in:
Peter Lai 2019-01-17 01:08:34 +08:00 committed by GitHub
commit 5e4e5e35fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 22 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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 $stream ;
*/
$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);