脚本宝典收集整理的这篇文章主要介绍了php – proc_open离开僵尸进程,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
问题是当用户关闭浏览器时,inotifywait进程保持打开状态,依此类推.
有什么方法可以避免这种情况吗?
<?PHP $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"; } ?>
所以基本上,您应该使用stream_set_blocking($pipes[1],0)
从子进程’stdout管道非阻塞模式读取数据,或者手动检查该管道上是否存在数据为stream_select()
.
此外,您需要使用ignore_user_abort(true)忽略用户中止.
以上是脚本宝典为你收集整理的php – proc_open离开僵尸进程全部内容,希望文章能够帮你解决php – proc_open离开僵尸进程所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。