为什么 shell_exec 执行多个进程?
我不明白为什么当我从浏览器运行 run.php
一次时有超过 1 个进程
在 PHP 代码中,我有以下内容:
run.php
<?php
shell_exec("php theprocess.php > /dev/null 2>&1 &");
?>
theprocess.php
<?php
$z = 1;
while ($z <= 20) {
echo $z . "\n";
$z++;
sleep(3);
}
?>
我从浏览器执行 run.php (例如: http://localhost/run.php)
然后我输入: ps aux | grep php
username@ [~]# ps aux | grep php
username 27272 0.0 1.5 89504 64468 ? R 17:33 0:00 php theprocess.php
username 27274 0.0 1.2 89504 49872 ? R 17:33 0:00 php theprocess.php
username 27276 0.0 0.6 89504 28676 ? R 17:33 0:00 php theprocess.php
username 27278 0.0 0.0 22280 3704 ? R 17:33 0:00 php theprocess.php
username 27280 0.0 0.0 1940 508 ? S+ 17:33 0:00 grep php
我不明白为什么它显示超过 1 个 theprocess.php 进程?
另外为什么它仍然在后台运行?它应该终止 theprocess.php
完成任务。那怎么办呢?
I dont understand why there is more than 1 process when I run run.php
once from a browser
In the PHP code, I have the following:
run.php
<?php
shell_exec("php theprocess.php > /dev/null 2>&1 &");
?>
theprocess.php
<?php
$z = 1;
while ($z <= 20) {
echo $z . "\n";
$z++;
sleep(3);
}
?>
I execute run.php from the browser (eg: http://localhost/run.php)
Then I typed: ps aux | grep php
username@ [~]# ps aux | grep php
username 27272 0.0 1.5 89504 64468 ? R 17:33 0:00 php theprocess.php
username 27274 0.0 1.2 89504 49872 ? R 17:33 0:00 php theprocess.php
username 27276 0.0 0.6 89504 28676 ? R 17:33 0:00 php theprocess.php
username 27278 0.0 0.0 22280 3704 ? R 17:33 0:00 php theprocess.php
username 27280 0.0 0.0 1940 508 ? S+ 17:33 0:00 grep php
I dont understand why is it showing more than 1 theprocess.php process?
Also why it still running at the background? it should terminate theprocess.php
finish the task. How can that be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了问题!
从网页运行脚本时,它不会被视为 PHP cli。
替换
为
我不再有多个进程在后台运行。
I have fixed the problem!
When running script from a webpage, it does not treat as PHP cli.
Replace
To
I no longer have multiple procress running in the background.