php proc open 返回,php – proc_open离开僵尸进程

以下脚本监视/ dev / shm / test以查找新文件并实时输出有关它的信息.

问题是当用户关闭浏览器时,inotifywait进程保持打开状态,依此类推.

有什么方法可以避免这种情况吗?

$descriptorspec = array(

0 => array("pipe", "r"), // stdin is a pipe that the child will read from

1 => array("pipe", "w"), // stdout is a pipe that the child will write to

2 => array("pipe", "a") // stderr is a file to write to

);

$process = proc_open('inotifywait -mc -e create /dev/shm/test/', $descriptorspec, $pipes);

if (is_resource($process)) {

header("Content-type: text/html;charset=utf-8;");

ob_end_flush(); //ends the automatic ob started by PHP

while ($s = fgets($pipes[1])) {

print $s;

flush();

}

fclose($pipes[1]);

fclose($pipes[0]);

fclose($pipes[2]);

// It is important that you close any pipes before calling

// proc_close in order to avoid a deadlock

$return_value = proc_close($process);

echo "command returned $return_value\n";

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值