变更
This commit is contained in:
+6
-6
@@ -47,7 +47,7 @@ abstract class ClientAbstracts implements IClient
|
|||||||
private int $port = 80;
|
private int $port = 80;
|
||||||
|
|
||||||
|
|
||||||
private array $_responseHeader = [];
|
private ?array $_responseHeader = [];
|
||||||
|
|
||||||
|
|
||||||
private int $statusCode = 200;
|
private int $statusCode = 200;
|
||||||
@@ -58,7 +58,7 @@ abstract class ClientAbstracts implements IClient
|
|||||||
protected int $retryTimeout = 0;
|
protected int $retryTimeout = 0;
|
||||||
|
|
||||||
|
|
||||||
private bool $VERIFYPEER = TRUE;
|
private bool $verifyPeer = TRUE;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,7 +124,7 @@ abstract class ClientAbstracts implements IClient
|
|||||||
*/
|
*/
|
||||||
public function withVerifyPeer($bool): static
|
public function withVerifyPeer($bool): static
|
||||||
{
|
{
|
||||||
$this->VERIFYPEER = $bool;
|
$this->verifyPeer = $bool;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ abstract class ClientAbstracts implements IClient
|
|||||||
*/
|
*/
|
||||||
public function getVerifyPeer(): bool
|
public function getVerifyPeer(): bool
|
||||||
{
|
{
|
||||||
return $this->VERIFYPEER;
|
return $this->verifyPeer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -167,9 +167,9 @@ abstract class ClientAbstracts implements IClient
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $responseHeader
|
* @param null|array $responseHeader
|
||||||
*/
|
*/
|
||||||
public function setResponseHeader(array $responseHeader): void
|
public function setResponseHeader(?array $responseHeader): void
|
||||||
{
|
{
|
||||||
$this->_responseHeader = $responseHeader;
|
$this->_responseHeader = $responseHeader;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-2
@@ -12,6 +12,7 @@ namespace Kiri;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Abstracts\Logger;
|
use Kiri\Abstracts\Logger;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Swoole\Coroutine\Http\Client as SwowClient;
|
use Swoole\Coroutine\Http\Client as SwowClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,9 +82,19 @@ class CoroutineClient extends ClientAbstracts
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function execute($path, $data)
|
private function execute($path, $data): void
|
||||||
{
|
{
|
||||||
$this->client->execute($this->setParams($path, $data));
|
$this->client->execute($this->setParams($path, $data));
|
||||||
|
if ($this->client->statusCode < 1) {
|
||||||
|
$logger = Kiri::getDi()->get(LoggerInterface::class);
|
||||||
|
|
||||||
|
$errMsg = sprintf("%s://%s:%s/%s -> error: %s", $this->isSSL() ? "https" : "http",
|
||||||
|
$this->getHost(), $this->getPort(), $path, $this->client->errMsg);
|
||||||
|
|
||||||
|
$errMsg .= print_r($data, true);
|
||||||
|
|
||||||
|
$logger->error($errMsg);
|
||||||
|
}
|
||||||
if (in_array($this->client->getStatusCode(), [502, 404])) {
|
if (in_array($this->client->getStatusCode(), [502, 404])) {
|
||||||
$this->retry($path, $data);
|
$this->retry($path, $data);
|
||||||
} else {
|
} else {
|
||||||
@@ -95,10 +106,12 @@ class CoroutineClient extends ClientAbstracts
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param $path
|
||||||
|
* @param $data
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function retry($path, $data)
|
private function retry($path, $data): void
|
||||||
{
|
{
|
||||||
if (Context::increment('retry') <= $this->retryNum) {
|
if (Context::increment('retry') <= $this->retryNum) {
|
||||||
sleep($this->retryTimeout);
|
sleep($this->retryTimeout);
|
||||||
|
|||||||
Reference in New Issue
Block a user