简体   繁体   English

尝试从Web脚本调用PHP CLI脚本会导致Apache产生多个子进程

[英]Trying to call a PHP CLI script from a web script causes Apache to spawn multiple child processes

Having read loads of threads about calling a long-running PHP CLI script from a web script, and the best way to daemonize the CLI script, I have hit an insoluble problem with the way Apache handles the CLI script. 阅读了有关从Web脚本调用长期运行的PHP CLI脚本的线程信息,以及守护CLI脚本的最佳方法,我遇到了Apache处理CLI脚本的方式的难题。 According to this blog post , the best option is to do something like : 根据此博客文章 ,最佳选择是执行以下操作:

print `echo /usr/bin/php -q longThing.php | at now`;

When I do this on my local CentOS 7/PHP 7/Apache 2.4.6 VM, it works like a charm, however, the identical code on my production server Centos 6.8/PHP 7/Apache 2.4.25 (cPanel) causes Apache to spawn 100s of child processes, rapidly exhausting the CPU and memory resources, requiring a reboot to fix. 当我在本地CentOS 7 / PHP 7 / Apache 2.4.6 VM上执行此操作时,它就像一个超级按钮,但是,生产服务器Centos 6.8 / PHP 7 / Apache 2.4.25(cPanel)上的相同代码导致Apache产生100个子进程,迅速耗尽CPU和内存资源,需要重新启动才能修复。 Even if I quickly kill the PHP CLI process, Apache has already got itself into some kind of loop. 即使我很快终止了PHP CLI进程,Apache还是陷入了某种循环。 My understanding was that by using the suggested code above, you disassociated Apache from the CLI process, but clearly not. 我的理解是,通过使用上面建议的代码,您使Apache与CLI进程脱离了联系,但显然没有。 Can anyone point me toward what is going wrong ? 谁能指出我出了什么问题? I can post the actual code and more details of my production server if needed. 如果需要,我可以发布实际代码以及生产服务器的更多详细信息。 Thanks 谢谢

Test this: 测试一下:

php file called xyz.php php文件名为xyz.php

<?php
shell_exec('php -r "sleep(20);" >> /dev/null 2>&1 &');

then run under command line 然后在命令行下运行

php xyz.php

And it is equal behavior if you call it from an browser. 如果从浏览器中调用它,则行为相同。

xyz.php will finish and not wait 20 seconds. xyz.php将完成,而不等待20秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM