首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
worker进程不断被重启
使用官网推荐的swoole-yaf框架,启动服务后 发现worker进程在不断重启,worker启动后会自动执行默认的controller action。master和manager 是稳定的{{{ class HttpServer { public static $instance; public $http; public static $get; public static $post; public static $header; public static $server; private $application; public $processName = 'HttpServer'; public function __construct() { $http = new swoole_http_server("172.30.102.41", 9501); $http->set( array( 'worker_num' => 4, 'daemonize' => false, 'max_request' => 1000, 'dispatch_mode' => 1 ) ); $http->on('Start', array($this, 'onMasterStart')); $http->on('ManagerStart', array($this, 'onManagerStart')); $http->on('WorkerStart' , array( $this , 'onWorkerStart')); $http->on('request', function ($request, $response) { if( isset($request->server) ) { HttpServer::$server = $request->server; }else{ HttpServer::$server = []; } if( isset($request->header) ) { HttpServer::$header = $request->header; }else{ HttpServer::$header = []; } if( isset($request->get) ) { HttpServer::$get = $request->get; }else{ HttpServer::$get = []; } if( isset($request->post) ) { HttpServer::$post = $request->post; }else{ HttpServer::$post = []; } ob_start(); try { $yaf_request = new Yaf_Request_Http( HttpServer::$server['request_uri']); $this->application ->getDispatcher()->dispatch($yaf_request); } catch ( Yaf_Exception $e ) { var_dump( $e ); } $result = ob_get_contents(); ob_end_clean(); $response->end($result); }); $http->setGlobal(HTTP_GLOBAL_ALL); $http->start(); } public function onMasterStart($server) { swoole_set_process_name($this->processName.' master process'); } public function onWorkerStart($server, $workerId) { swoole_set_process_name($this->processName.' worker process'); define('APPLICATION_PATH', dirname(__DIR__)); $this->application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini"); ob_start(); try { $this->application->bootstrap()->run(); } catch(Yaf_Exception $e) { var_dump($e); } ob_end_clean(); } public function onManagerStart($server) { swoole_set_process_name($this->processName.' manager process'); } public static function getInstance() { if (!self::$instance) { self::$instance = new HttpServer; } return self::$instance; } } HttpServer::getInstance(); }}} {{{ [vagrant@localhost ~]$ ps uax | grep HttpServer vagrant 12430 0.2 2.3 445548 23988 pts/2 Sl+ 07:46 0:00 HttpServer master process vagrant 12431 2.7 0.6 369360 6296 pts/2 S+ 07:46 0:00 HttpServer manager process vagrant 13378 0.0 0.6 187024 6872 pts/2 R+ 07:46 0:00 HttpServer worker process vagrant 13379 0.0 0.7 253348 7236 pts/2 R+ 07:46 0:00 HttpServer worker process vagrant 13380 0.0 0.7 365720 7348 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13382 0.0 0.0 103320 908 pts/1 S+ 07:46 0:00 grep HttpServer [vagrant@localhost ~]$ ps uax | grep HttpServer vagrant 12430 0.2 2.3 445548 23988 pts/2 Sl+ 07:46 0:00 HttpServer master process vagrant 12431 2.6 0.6 369360 6296 pts/2 S+ 07:46 0:00 HttpServer manager process vagrant 13477 0.0 0.7 356884 7864 pts/2 R+ 07:46 0:00 HttpServer worker process vagrant 13478 0.0 0.7 365720 7348 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13479 0.0 0.7 365720 7280 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13480 0.0 0.7 365720 7236 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13482 0.0 0.0 103320 908 pts/1 S+ 07:46 0:00 grep HttpServer }}}
发布于7年前 · 3 次浏览 · 来自
提问
.
.chen
使用官网推荐的swoole-yaf框架,启动服务后 发现worker进程在不断重启,worker启动后会自动执行默认的controller action。master和manager 是稳定的{{{ class HttpServer { public static $instance; public $http; public static $get; public static $post; public static $header; public static $server; private $application; public $processName = 'HttpServer'; public function __construct() { $http = new swoole_http_server("172.30.102.41", 9501); $http->set( array( 'worker_num' => 4, 'daemonize' => false, 'max_request' => 1000, 'dispatch_mode' => 1 ) ); $http->on('Start', array($this, 'onMasterStart')); $http->on('ManagerStart', array($this, 'onManagerStart')); $http->on('WorkerStart' , array( $this , 'onWorkerStart')); $http->on('request', function ($request, $response) { if( isset($request->server) ) { HttpServer::$server = $request->server; }else{ HttpServer::$server = []; } if( isset($request->header) ) { HttpServer::$header = $request->header; }else{ HttpServer::$header = []; } if( isset($request->get) ) { HttpServer::$get = $request->get; }else{ HttpServer::$get = []; } if( isset($request->post) ) { HttpServer::$post = $request->post; }else{ HttpServer::$post = []; } ob_start(); try { $yaf_request = new Yaf_Request_Http( HttpServer::$server['request_uri']); $this->application ->getDispatcher()->dispatch($yaf_request); } catch ( Yaf_Exception $e ) { var_dump( $e ); } $result = ob_get_contents(); ob_end_clean(); $response->end($result); }); $http->setGlobal(HTTP_GLOBAL_ALL); $http->start(); } public function onMasterStart($server) { swoole_set_process_name($this->processName.' master process'); } public function onWorkerStart($server, $workerId) { swoole_set_process_name($this->processName.' worker process'); define('APPLICATION_PATH', dirname(__DIR__)); $this->application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini"); ob_start(); try { $this->application->bootstrap()->run(); } catch(Yaf_Exception $e) { var_dump($e); } ob_end_clean(); } public function onManagerStart($server) { swoole_set_process_name($this->processName.' manager process'); } public static function getInstance() { if (!self::$instance) { self::$instance = new HttpServer; } return self::$instance; } } HttpServer::getInstance(); }}} {{{ [vagrant@localhost ~]$ ps uax | grep HttpServer vagrant 12430 0.2 2.3 445548 23988 pts/2 Sl+ 07:46 0:00 HttpServer master process vagrant 12431 2.7 0.6 369360 6296 pts/2 S+ 07:46 0:00 HttpServer manager process vagrant 13378 0.0 0.6 187024 6872 pts/2 R+ 07:46 0:00 HttpServer worker process vagrant 13379 0.0 0.7 253348 7236 pts/2 R+ 07:46 0:00 HttpServer worker process vagrant 13380 0.0 0.7 365720 7348 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13382 0.0 0.0 103320 908 pts/1 S+ 07:46 0:00 grep HttpServer [vagrant@localhost ~]$ ps uax | grep HttpServer vagrant 12430 0.2 2.3 445548 23988 pts/2 Sl+ 07:46 0:00 HttpServer master process vagrant 12431 2.6 0.6 369360 6296 pts/2 S+ 07:46 0:00 HttpServer manager process vagrant 13477 0.0 0.7 356884 7864 pts/2 R+ 07:46 0:00 HttpServer worker process vagrant 13478 0.0 0.7 365720 7348 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13479 0.0 0.7 365720 7280 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13480 0.0 0.7 365720 7236 pts/2 D+ 07:46 0:00 HttpServer worker process vagrant 13482 0.0 0.0 103320 908 pts/1 S+ 07:46 0:00 grep HttpServer }}}
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2017-07-01
k
kang
检查swoole log_file中日志,观察是否有致命错误、exit/die、core dump导致worker进程退出。
赞
1
回复
2021-02-24
风
风格
请问解决了吗,。我也遇到了,无从下手
赞
0
回复
微信公众号
热门内容
暂无回复的问答
- 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一直是同一个。没用使用到多进程啊。