in consumer/fsof/FSOFProcessor.php [47:167]
public function executeRequest(DubboRequest $request, $svrAddr, $ioTimeOut, &$providerAddr)
{
$this->iotimeout = $ioTimeOut;
//计算服务端个数
$svrNum = count($svrAddr);
//连接异常重试次数最多2次
$connect_try_times = ($svrNum > 2) ? 2 : $svrNum;
$client = NULL;
for ($i = 0; $i < $connect_try_times; $i++)
{
try
{
//获取路由下标
$col = mt_rand(0, $svrNum-1);
$svrUrl = $svrAddr[$col];
$host = $svrUrl->getHost();
$port = $svrUrl->getPort();
//记录路由信息
$providerAddr = $host.':'.$port;
//透传到服务端字段
$request->host = $host;
$request->port = $port;
$request->setGroup($svrUrl->getGroup());
$request->setVersion( $svrUrl->getVersion());
$request->setTimeout($this->iotimeout * 1000);
$request->setSerialization($svrUrl->getSerialization(DubboParser::DUBBO_PROTOCOL_SERIALIZE_FAST_JSON));
$client = $this->connectProvider($host, $port, $this->iotimeout);
if(empty($client))
{
//记录连接错误日志
$this->logger->error("connect FSOF server[".$host.":".$port ."] failed");
//删除无用地址信息
$svrAddr[$col] = NULL;
$svrAddr = array_filter($svrAddr);
if(self::FSOF_ECONNREFUSED == $this->lastErrorNo)
{
//连接拒绝
continue;
}
else if(self::FSOF_ETIMEOUT == $this->lastErrorNo || self::FSOF_EINPROGRESS == $this->lastErrorNo)
{
//连接超时
break;
}
else
{
//其他错误
continue;
}
}
else
{
break;
}
}
catch (\Exception $e)
{
if (!empty($client))
{
unset($client);
}
$this->logger->error($e->getMessage(), $e);
}
}
//与服务端进行交互
$ret = NULL;
if(isset($client))
{
try
{
$data = $this->parser->packRequest($request);
$dataLen = strlen($data);
if(!$client->send($data, $dataLen))
{
$client->close(true);
unset($client);
$msg = json_encode($request->__toString(), JSON_UNESCAPED_UNICODE);
if (mb_strlen($msg, 'UTF-8') >= 512)
{
$msg = mb_substr($msg, 0, 512, 'UTF-8').' ...(len:'.strlen($msg).")";
}
$this->logger->error("send date failed:" . $msg);
throw new ConsumerException("发送请求数据失败");
}
}
catch (\Exception $e)
{
$client->close(true);
unset($client);
$msg = json_encode($request->__toString(), JSON_UNESCAPED_UNICODE);
if (mb_strlen($msg, 'UTF-8') >= 512)
{
$msg = mb_substr($msg, 0, 512, 'UTF-8').' ...(len:'.strlen($msg).")";
}
$this->logger->error("send date failed:" . $msg, $e);
throw new ConsumerException("发送请求数据失败");
}
try
{
$ret = $this->recvDataFromProvider($client, $request);
$client->close();
unset($client);
}
catch (\Exception $e)
{
$client->close(true);
unset($client);
throw $e;
}
}
else
{
throw new ConsumerException("与服务器建立连接失败");
}
return $ret;
}