PHP+Swoole+Linux实现进程监控

class Server
{
    const PORT = 8888;

    public function port()
    {
        //netstat -anp 2>/dev/null| grep 8888 |grep LISTEN |wc -l
        $shellCommand = 'netstat -anp 2>/dev/null| grep ' . self::PORT . "| grep LISTEN | wc -l";
        $result = shell_exec($shellCommand);
        if ($result != 1) {
            //进程不存在,发送警报信息
            echo 'At '.date('Y-m-d H:i:s') . ' service process is exit' . PHP_EOL;
        } else {
            echo 'At '.date('Y-m-d H:i:s') . ' service process is ok' . PHP_EOL;
        }
    }

}

Swoole\Timer::tick(1000, function (int $timer_id) {
    (new Server)->port();
});

nohup /usr/bin/php ./Server.php > ~/test.log &

创新互联建站从2013年开始,是专业互联网技术服务公司,拥有项目网站建设、成都网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元朝阳做网站,已为上家服务,为朝阳各地企业和个人服务,联系电话:028-86922220

更加精确的写法
netstat -anp 2>/dev/null| grep 127.0.0.1:8866 | grep LISTEN | wc -l


当前名称:PHP+Swoole+Linux实现进程监控
文章地址:http://lszwz.com/article/pccgeo.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款