代码脚本
<?php
class ListeningPort{
const PORT=9601;
public function port()
{
$shell = "netstat -anp | grep ". self::PORT . " | grep LISTEN | wc -l";
$res = shell_exec($shell);
if($res != 1){
echo date("Y-m-d H:i:s") ." error ".PHP_EOL;
}else{
echo date("Y-m-d H:i:s") ." success ".PHP_EOL;
}
}
}
swoole_timer_tick(2000,function($timer_id){
echo "执行了";
(new ListeningPort())->port();
});
运行
nohup php listeningPort.php > 1.txt