首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
突然出现大量的operation now in progress
### 问题描述 代码用着用着出现大量的operation now in progress exception 'think\exception\ErrorException' with message 'swoole_client::connect(): connect to server[127.0.0.1:9505] failed. Error: Operation now in progress[115].' in /data/www/api/application/common/controller/SwooleClient.php:54 ### Swoole版本,PHP版本,以及操作系统版本信息 swoole版本:1.10.4 PHP:5.6.40 Linux version 2.6.32-754.35.1.el6.x86_64 ### 相关代码 ```php <?php /** * Created by PhpStorm. * User: lenovo * Date: 2018/4/13 * Time: 9:34 */ namespace app\common\controller; use think\Exception; class SwooleClient { public $cli = null; private $is_long = false; private $connected = true; private $config = [ 'host' => '127.0.0.1', 'port' => 9502, 'sock_type' => 1, //sock类型,tcp 'sock_sync' => 0 //同步客户端 ]; private $cliconfig = [ 'socket_buffer_size' => 3145728, 'open_length_check' => 1, 'package_length_type' => 'N', 'package_length_offset' => 0, //第N个字节是包长度的值 'package_body_offset' => 4, //第几个字节开始计算长度 'package_max_length' => 2000000, //协议最大长度 ]; public function __construct($config = [], $is_long = false) { $this->config = array_merge($this->config, $config); $this->is_long = $is_long; $sock_type = $this->is_long ? SWOOLE_SOCK_TCP | SWOOLE_KEEP : $this->config['sock_type']; $this->cli = new \swoole_client($sock_type, $this->config['sock_sync']); $this->cli->set($this->cliconfig); if (!empty($this->config['host']) && !empty($this->config['port'])) { $this->connect($this->config['host'], $this->config['port']); } } public function connect($host = '127.0.0.1', $port = 9502) { if ($this->cli->connect($host, $port, 3) === false) { _set_log('swoole::client connect fail'.$this->cli->errCode, 'error'); $this->close(); $re = $this->cli->connect($host, $port, 3); if ($re === false) { $this->connected = false; } } } public function send($data, $package = false) { $data = is_array($data) || is_object($data) ? json_encode($data) : $data; if ($package === true) { $pack = pack('N', strlen($data)); $data = $pack. $data; } try { return $this->cli->send($data); } catch (Exception $e) { $this->close(); $this->connect($this->config['host'], $this->config['port']); $re = $this->cli->send($data); } return $re; } public function recv() { $data = $this->cli->recv(); if (isset($this->cliconfig['open_length_check'])) { $len = unpack('N', $data)[1]; $data = mb_substr($data, -$len); } return $data; } public function close() { $this->cli->close($this->is_long); } private function __clone() { // TODO: Implement __clone() method. } } ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待的结果:为啥会突然出现这种报错,以后怎么规避。
发布于4年前 · 12 次浏览 · 来自
提问
c
cccccwww
### 问题描述 代码用着用着出现大量的operation now in progress exception 'think\exception\ErrorException' with message 'swoole_client::connect(): connect to server[127.0.0.1:9505] failed. Error: Operation now in progress[115].' in /data/www/api/application/common/controller/SwooleClient.php:54 ### Swoole版本,PHP版本,以及操作系统版本信息 swoole版本:1.10.4 PHP:5.6.40 Linux version 2.6.32-754.35.1.el6.x86_64 ### 相关代码 ```php <?php /** * Created by PhpStorm. * User: lenovo * Date: 2018/4/13 * Time: 9:34 */ namespace app\common\controller; use think\Exception; class SwooleClient { public $cli = null; private $is_long = false; private $connected = true; private $config = [ 'host' => '127.0.0.1', 'port' => 9502, 'sock_type' => 1, //sock类型,tcp 'sock_sync' => 0 //同步客户端 ]; private $cliconfig = [ 'socket_buffer_size' => 3145728, 'open_length_check' => 1, 'package_length_type' => 'N', 'package_length_offset' => 0, //第N个字节是包长度的值 'package_body_offset' => 4, //第几个字节开始计算长度 'package_max_length' => 2000000, //协议最大长度 ]; public function __construct($config = [], $is_long = false) { $this->config = array_merge($this->config, $config); $this->is_long = $is_long; $sock_type = $this->is_long ? SWOOLE_SOCK_TCP | SWOOLE_KEEP : $this->config['sock_type']; $this->cli = new \swoole_client($sock_type, $this->config['sock_sync']); $this->cli->set($this->cliconfig); if (!empty($this->config['host']) && !empty($this->config['port'])) { $this->connect($this->config['host'], $this->config['port']); } } public function connect($host = '127.0.0.1', $port = 9502) { if ($this->cli->connect($host, $port, 3) === false) { _set_log('swoole::client connect fail'.$this->cli->errCode, 'error'); $this->close(); $re = $this->cli->connect($host, $port, 3); if ($re === false) { $this->connected = false; } } } public function send($data, $package = false) { $data = is_array($data) || is_object($data) ? json_encode($data) : $data; if ($package === true) { $pack = pack('N', strlen($data)); $data = $pack. $data; } try { return $this->cli->send($data); } catch (Exception $e) { $this->close(); $this->connect($this->config['host'], $this->config['port']); $re = $this->cli->send($data); } return $re; } public function recv() { $data = $this->cli->recv(); if (isset($this->cliconfig['open_length_check'])) { $len = unpack('N', $data)[1]; $data = mb_substr($data, -$len); } return $data; } public function close() { $this->cli->close($this->is_long); } private function __clone() { // TODO: Implement __clone() method. } } ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待的结果:为啥会突然出现这种报错,以后怎么规避。
赞
1
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2021-10-22
Rango
原因比较多,可能是服务器丢弃`TCP SYN`包了,查看服务器的相关日志,客户端可以重连一次。
赞
0
回复
2021-10-29
c
cccccwww
回复
Rango
大佬,应该怎么查服务器相关日志啊。
赞
0
回复