改名
This commit is contained in:
@@ -16,6 +16,7 @@ use Snowflake\Snowflake;
|
|||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Swoole\Coroutine\Http\Client as SClient;
|
use Swoole\Coroutine\Http\Client as SClient;
|
||||||
use Swoole\Coroutine\System;
|
use Swoole\Coroutine\System;
|
||||||
|
use Swoole\Coroutine\Client as SCClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Client
|
* Class Client
|
||||||
@@ -234,21 +235,17 @@ class Client
|
|||||||
*/
|
*/
|
||||||
public function sendTo($path, array $data, $type = SWOOLE_TCP)
|
public function sendTo($path, array $data, $type = SWOOLE_TCP)
|
||||||
{
|
{
|
||||||
$client = new \Swoole\Coroutine\Client($type);
|
$client = new SCClient($type);
|
||||||
if (empty($this->host) || empty($this->port)) {
|
if (empty($this->host) || empty($this->port)) {
|
||||||
return new Result(['code' => 500, 'message' => 'Host and port is null']);
|
return new Result(['code' => 500, 'message' => 'Host and port is null']);
|
||||||
}
|
}
|
||||||
if (!$client->connect($this->host, $this->port, $this->connect_timeout)) {
|
if (!$client->connect($this->host, $this->port, $this->connect_timeout)) {
|
||||||
return new Result(['code' => 500, 'message' => $client->errMsg]);
|
return new Result(['code' => 500, 'message' => $client->errMsg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = '/' . $this->port . '/' . ltrim($path, '/');
|
|
||||||
|
|
||||||
$params['body'] = $data;
|
$params['body'] = $data;
|
||||||
$params['path'] = $path;
|
$params['path'] = '/' . $this->port . '/' . ltrim($path, '/');
|
||||||
$params['header']['request_uri'] = $path;
|
$params['header']['request_uri'] = $params['path'];
|
||||||
$params['header']['request_method'] = 'receive';
|
$params['header']['request_method'] = 'receive';
|
||||||
|
|
||||||
if ($client->send(serialize($params))) {
|
if ($client->send(serialize($params))) {
|
||||||
$recv = $this->timeout > 0 ? $client->recv($this->timeout) : $client->recv();
|
$recv = $this->timeout > 0 ? $client->recv($this->timeout) : $client->recv();
|
||||||
$param = $this->structure(Help::toArray($recv), $data, null, 200);
|
$param = $this->structure(Help::toArray($recv), $data, null, 200);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Http2 extends Component
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function query($domain, $path, $params = [], $timeout = -1)
|
public function get($domain, $path, $params = [], $timeout = -1)
|
||||||
{
|
{
|
||||||
$client = $this->getClient($domain, $path, $timeout);
|
$client = $this->getClient($domain, $path, $timeout);
|
||||||
$client->send($this->getRequest($domain, $path, 'GET', $params));
|
$client->send($this->getRequest($domain, $path, 'GET', $params));
|
||||||
@@ -51,7 +51,7 @@ class Http2 extends Component
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function push($domain, $path, $params = [], $timeout = -1)
|
public function post($domain, $path, $params = [], $timeout = -1)
|
||||||
{
|
{
|
||||||
$client = $this->getClient($domain, $path, $timeout);
|
$client = $this->getClient($domain, $path, $timeout);
|
||||||
$client->send($this->getRequest($domain, $path, 'POST', $params));
|
$client->send($this->getRequest($domain, $path, 'POST', $params));
|
||||||
@@ -59,6 +59,40 @@ class Http2 extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $domain
|
||||||
|
* @param $path
|
||||||
|
* @param array $params
|
||||||
|
* @param int $timeout
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function delete($domain, $path, $params = [], $timeout = -1)
|
||||||
|
{
|
||||||
|
$client = $this->getClient($domain, $path, $timeout);
|
||||||
|
$client->send($this->getRequest($domain, $path, 'DELETE', $params));
|
||||||
|
return new Result(['code' => 0, 'data' => Help::toArray($client->recv())]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $domain
|
||||||
|
* @param $path
|
||||||
|
* @param array $params
|
||||||
|
* @param int $timeout
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function put($domain, $path, $params = [], $timeout = -1)
|
||||||
|
{
|
||||||
|
$client = $this->getClient($domain, $path, $timeout);
|
||||||
|
$client->send($this->getRequest($domain, $path, 'PUT', $params));
|
||||||
|
return new Result(['code' => 0, 'data' => Help::toArray($client->recv())]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $domain
|
* @param $domain
|
||||||
* @param $path
|
* @param $path
|
||||||
|
|||||||
Reference in New Issue
Block a user