class Server
{
const PORT = 8811;
public function port(){
//运行中返回1 没有返回0
$shell = "netstat -anp tcp| grep ". self::PORT ." |grep LISTEN | wc -l";
$result = shell_exec($shell);
if($result ==0){
echo "error";
}else{
echo "success";
}
}
}
Swoole\Timer::tick(2000,function ($timer_id){
(new Server())->port().PHP_EOL;
});
linux命令
//后台运行 并写入到文件
nohup /usr/local/php5/bin/php /users/w/work/Web/tp5/script/monitor/server.php > /users/w/work/Web/tp5/script/monitor/a.txt &