使用swoole+php监控服务器端口

<?php
class Server {
	const PORT = 80;
	
	public function port() {
		$shell = "netstat -anp 2>/dev/null | grep ".self::PORT." | grep LISTEN | wc -l";
		
		$result = shell_exec($shell);
		
		if($result <> 1) {
			echo date("ymd H:i:s")."error".PHP_EOL;
		} else {
			echo date("ymd H:i:s")."success".PHP_EOL;
		}
	}
}
swoole_timer_tick(2000, function($timer_id) {
	(new Server())->port();
	echo "time-start".PHP_EOL;
});