$PORT=8080;
$shell = "netstat -anp 2>/dev/null | grep ". PORT . " | grep LISTEN | wc -l"; $result = shell_exec($shell); if($result != 1) { /// todo echo "error"; } else { echo "succss"; }
说明
2>/dev/null 把多余信息输出到dev/null
grep LISTEN 再管道过虑一次条件
wc -l 统计行数