Home
Download
Document
Forum
Video
Donate
Source Code
AI 助理
Sponsors
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
Products
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
Login
Register
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
swoole http服务,请求出现socket hang up
### postman请求出现socket hang up ### 4.6.7,7.4,centos7 ### 相关代码 ```php public function onManagerStart() { if (self::$daemonize) { Process::daemon(); } $pool->set(['enable_coroutine' => true]); $pool->on('WorkerStart', [$this, 'onWorkerStart']); $pool->start(); return true; } public function onWorkerStart(Process\Pool $pool, $workerId) { $server = new Server($this->ip, $this->port, false, true); $server->handle('/api/', [$this, 'onRequest']); $server->start(); } public function onRequest(Swoole\Http\Request $request, Swoole\Http\Response $response) { ini_set('memory_limit', '-1'); ini_set('display_errors', 'On'); //是否显示错误 ini_set('error_reporting', E_ALL); //设置错误的报告级别 $response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); $response->header('Access-Control-Allow-Methods', 'GET, POST, PUT'); $response->header('Access-Control-Allow-Origin', '*'); //解决跨域 $response->header('Content-Type', 'application/json'); //注册全局信息 $this->initRequestParam($request); Yaf\Registry::set('SWOOLE_HTTP_REQUEST', $request); Yaf\Registry::set('SWOOLE_HTTP_RESPONSE', $response); ob_start(); $route = $request->server['request_uri'] ?? ''; $requestRoute = \Yaf\Registry::get('routeConf')->$route['url'] ?? ''; if ($requestRoute) { $yafRequest = new Yaf\Request\Http($requestRoute); $configArr = Yaf\Application::app()->getConfig()->toArray(); if (!empty($configArr['application']['baseUri'])) { $yafRequest->setBaseUri($configArr['application']['baseUri']); } //关闭视图 Yaf\Dispatcher::getInstance()->autoRender(FALSE); $this->app->getDispatcher()->dispatch($yafRequest); $result = ob_get_contents(); ob_end_clean(); //返回数据处理 $result = $result ? json_decode($result, true) : []; } else { $result = ['code' => 0, 'message' => '404 not found', 'data' => [], 'status' => 404]; } $status = 200; if (isset($result['status']) && $result['status']) { $status = $result['status']; unset($result['status']); } $response->status($status); $response->end(json_encode($result)); } ``` ### 启动后,用postman请求一切正常,但是请求后停止一两分钟,再次请求,第一次必出现socket hang up,之后请求又是正常的,请问这个是代码问题还是postman工具问题?
发布于3年前 · 21 次浏览 · 来自
提问
JKD
### postman请求出现socket hang up ### 4.6.7,7.4,centos7 ### 相关代码 ```php public function onManagerStart() { if (self::$daemonize) { Process::daemon(); } $pool->set(['enable_coroutine' => true]); $pool->on('WorkerStart', [$this, 'onWorkerStart']); $pool->start(); return true; } public function onWorkerStart(Process\Pool $pool, $workerId) { $server = new Server($this->ip, $this->port, false, true); $server->handle('/api/', [$this, 'onRequest']); $server->start(); } public function onRequest(Swoole\Http\Request $request, Swoole\Http\Response $response) { ini_set('memory_limit', '-1'); ini_set('display_errors', 'On'); //是否显示错误 ini_set('error_reporting', E_ALL); //设置错误的报告级别 $response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); $response->header('Access-Control-Allow-Methods', 'GET, POST, PUT'); $response->header('Access-Control-Allow-Origin', '*'); //解决跨域 $response->header('Content-Type', 'application/json'); //注册全局信息 $this->initRequestParam($request); Yaf\Registry::set('SWOOLE_HTTP_REQUEST', $request); Yaf\Registry::set('SWOOLE_HTTP_RESPONSE', $response); ob_start(); $route = $request->server['request_uri'] ?? ''; $requestRoute = \Yaf\Registry::get('routeConf')->$route['url'] ?? ''; if ($requestRoute) { $yafRequest = new Yaf\Request\Http($requestRoute); $configArr = Yaf\Application::app()->getConfig()->toArray(); if (!empty($configArr['application']['baseUri'])) { $yafRequest->setBaseUri($configArr['application']['baseUri']); } //关闭视图 Yaf\Dispatcher::getInstance()->autoRender(FALSE); $this->app->getDispatcher()->dispatch($yafRequest); $result = ob_get_contents(); ob_end_clean(); //返回数据处理 $result = $result ? json_decode($result, true) : []; } else { $result = ['code' => 0, 'message' => '404 not found', 'data' => [], 'status' => 404]; } $status = 200; if (isset($result['status']) && $result['status']) { $status = $result['status']; unset($result['status']); } $response->status($status); $response->end(json_encode($result)); } ``` ### 启动后,用postman请求一切正常,但是请求后停止一两分钟,再次请求,第一次必出现socket hang up,之后请求又是正常的,请问这个是代码问题还是postman工具问题?
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
还没有评论!
微信公众号
热门内容
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。