Commit 5d222e8e authored by tufengqi's avatar tufengqi

异步优化

parent de54f0fd
...@@ -92,6 +92,8 @@ class TGuzzleClient extends \Thrift\Transport\TTransport ...@@ -92,6 +92,8 @@ class TGuzzleClient extends \Thrift\Transport\TTransport
protected $uri_no_func; protected $uri_no_func;
static private $guzzle_client;
/** /**
* Make a new HTTP client. * Make a new HTTP client.
* *
...@@ -115,6 +117,9 @@ class TGuzzleClient extends \Thrift\Transport\TTransport ...@@ -115,6 +117,9 @@ class TGuzzleClient extends \Thrift\Transport\TTransport
$this->timeout_ = null; $this->timeout_ = null;
$this->response_body = ''; $this->response_body = '';
$this->headers_ = []; $this->headers_ = [];
if (!self::$guzzle_client) {
self::$guzzle_client = new \GuzzleHttp\Client();
}
} }
public function setFuncUri($uri_func) public function setFuncUri($uri_func)
...@@ -217,8 +222,7 @@ class TGuzzleClient extends \Thrift\Transport\TTransport ...@@ -217,8 +222,7 @@ class TGuzzleClient extends \Thrift\Transport\TTransport
], ],
'timeout' => number_format($this->timeout_ / 1000, 1) // s 'timeout' => number_format($this->timeout_ / 1000, 1) // s
]; ];
$client = new \GuzzleHttp\Client(); $promise = self::$guzzle_client->sendAsync($request, $options)->then(function ($response) {
$promise = $client->sendAsync($request, $options)->then(function ($response) {
$this->response_ = $response->getBody()->getContents(); $this->response_ = $response->getBody()->getContents();
}); });
return $promise; return $promise;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment