具体代码如下所示:
<"主进程进程 $pid \n"; exit; }else if($pid == 0){ if(-1 === posix_setsid()){ throw new Exception("setsid fail"); } for ($i=0; $i < self::$count; $i++) { static::runWorker(); } @cli_set_process_title("master_process"); }else{ throw new Exception("创建主进程失败"); } } //开启子进程 public static function runWorker(){ unmask(0); $pid = pcntl_fork(); if($pid > 0){ // echo "创建子进程 $pid \n"; }else if($pid == 0){ if(-1 === posix_setsid()){ throw new Exception("setsid fail"); } @cli_set_process_title("worker_process"); while(1){ sleep(1); } }else{ throw new Exception("创建子进程失败"); } } //监控worker进程 public function moniProcess(){ while( $pid = pcntl_wait($status)){ if($pid == -1){ break; }else{ static::runWorker(); } } } } Worker::runAll();
ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 18200 3076 pts/0 Ss+ 14:05 0:00 bash root 6 0.0 0.0 18208 3252 pts/1 Ss 14:06 0:00 bash root 19 0.0 0.0 18204 3248 pts/2 Ss+ 14:11 0:00 bash root 64 0.0 0.2 348488 8320 "htmlcode">USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 18200 3076 pts/0 Ss+ 14:05 0:00 bash root 6 0.0 0.0 18208 3252 pts/1 Ss 14:06 0:00 bash root 19 0.0 0.0 18204 3248 pts/2 Ss+ 14:11 0:00 bash root 64 0.0 0.2 348488 8320 "color: #ff0000">总结以上所述是小编给大家介绍的php实现 master-worker 守护多进程模式的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】
- 林忆莲.2019-0(2023精装版)【环球】【WAV+CUE】
- Supper.Moment.2016-The.Moment【寰亚】【FLAC分轨】
- 范莉丝.1979-送郎一朵牵牛花(LP版)【大联机构】【WAV+CUE】