小白兔晒黑了

导航

 

视频地址 https://www.bilibili.com/video/BV14E411t7T4?p=22&spm_id_from=pageDriver&vd_source=4a69745b599dffec877b0fcfe130b092

僵尸进程

\pro\test2.php

<?php
$http = new Swoole\Http\Server('0.0.0.0',80);
//配置参数 https://wiki.swoole.com/#/server/setting
$http->set(array(
    'worker_num'=>1,     //设置启动的 Worker 进程数。【默认值:CPU 核数】
    'daemonize'=>false     // 使用docker 不需要设置守护进程
));
$http->on('request',function ($req,$res){

});
$http->start();

启动后会有3个进程

 

1个master经常(服务器主进程)

1个Manager进程

work _num个work进程

 

 

php内置变量 $argc $argv

比如 php test2.php start

则 $argc=2   、$argv=['test2.php','start']

<?php
use Swoole\Http\Server;
use Swoole\Process;

if ($argc==2){
    $cmd = $argv[1];
    if ($cmd=='start'){
        $http = new Swoole\Http\Server('0.0.0.0',80);
        //配置参数 https://wiki.swoole.com/#/server/setting
        $http->set(array(
          'worker_num'=>1,     //设置启动的 Worker 进程数。【默认值:CPU 核数】
          'daemonize'=>false     // 使用docker 不需要设置守护进程
        ));
        $http->on('request',function ($req,$res){
        
        });
    
        $http->on('Start',function (Server $server ){
            $mid =  $server->master_pid;   //返回当前服务器主进程的 PID。
            file_put_contents("./ttt.pid",$mid);  //会覆盖
        });
        $http->start();
    
    } elseif ($cmd=='stop'){
        $mid = intval(file_get_contents("./ttt.pid"));
        if (trim($mid)){
            Process::kill($mid);
        }
    } else {
        echo '无效命令';
    }
}   else {
    echo '无效命令';
}

 

重启容器 

docker exec -it 67e09c446436 sh

 

 

重新开一个窗口

 

 stop以后会出现     NOTICE    Server is shutdown now.

 

posted on 2022-07-04 01:56  小白兔晒黑了  阅读(59)  评论(0编辑  收藏  举报