没有从包含 exec() 的 do while 循环中出来
我有一个 php 脚本,它会触发三个 exec() 命令并获取它们各自的 pid。
我想等待所有三个 exec 命令停止运行,然后再进行下一批三个命令。
我尝试在 do while 循环中检查每个 pid,但它似乎永远不会脱离循环:它只是坐在那里直到脚本超时。
这是我尝试过的简化版本:
do {
$pid = 722;
print "checking";
exec("ps -p $pid", $output);
$count = count($output);
} while ( $count >= 2 );
print "out of do while";
有谁知道什么可能导致它永远不会退出循环?
I have a php script which fires off three exec() commands and gets their respective pids.
I'd like to wait for all three exec commands to stop running before moving onto the next batch of three.
I've tried checking each pid in a do while loop, but it never seems to come out of the loop: it just sits there until the script times out.
Here's a simplified version of what I tried:
do {
$pid = 722;
print "checking";
exec("ps -p $pid", $output);
$count = count($output);
} while ( $count >= 2 );
print "out of do while";
Does anyone have any ideas about what might cause it to never come out of the loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 的 exec 只是不断追加到数组中,因此计数只会增加。要覆盖输出数组,请在调用 exec 之前调用
unset($output)
。有关详细信息,请参阅 关于 exec 的 php 手册。
PHPs exec just keeps appending to the array, so the count will only increase. To overwrite the output array call
unset($output)
before calling exec.See the php manual on exec for more details.
来自
exec()
手册。From
exec()
manual.