通过php 来监听linux 服务是否开启

此处是通过端口是否开启来判断

linux shell

netstat -anp 2>/dev/null | grep 8811 | grep LISTEN | wc -l
2>/dev/null:将说明文字去除
grep 8811:抓取端口号
grep LISTEN :抓取监听行
  wc -l : 统计行数

php代码

$shell  =  "netstat -anp 2>/dev/null | grep 8811 | grep LISTEN | wc -l";

$result = shell_exec($shell);

如果没有开启则返回0

猜你喜欢

转载自blog.csdn.net/weixin_41858542/article/details/82459245