在循环内执行外部php文件
如果我有一个 while 循环,并在其中通过 system() 执行一个 php 文件,假设这个 php 文件需要很长时间才能完成(例如下载图像等),主脚本是否会等待该文件完成,直到转到下一个循环?
现在看起来它确实在等待当前脚本完成然后再进入下一个脚本,但我只是想确定一下。也许了解 PHP 内部原理的人可以提供一些线索。
谢谢。
If I have a while loop and inside it I execute a php file via system(), and let's say this php file takes long to finish (e.g. downloading images, etc), will the main script wait for that to finish until going to the next loop?
Now it looks like it's indeed waiting for the current script to finish before going to the next one but I just want to make sure. Maybe someone who knows the internals of PHP can shed some light.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
系统执行命令,然后挂起,直到命令执行完毕。
来自手册: http://php.net/manual/en/function.system.php
System executes the command and then hangs until the command is executed.
From the manual: http://php.net/manual/en/function.system.php
一旦 system() 命令完成,循环就会继续。解决这个问题的方法可能是用“&”开始 bg 作业
http://lowfatlinux.com/linux-processes.html
我假设您使用的是 Linux,我不知道 Windows 下有解决方法。
The loop will proceed once the system() command is done. A work around this might be to start the bg job with '&'
http://lowfatlinux.com/linux-processes.html
I am assuming you are using Linux, I am not aware of a workaround under windows.
如果brunoais和Sabeen Malik的方式不起作用,请一起尝试:
在Windows下我认为你可以使用启动命令:
If brunoais and Sabeen Malik way does not work, try both together:
Under windows I think you can use the start command:
另外,您应该使用 set_time_limit,否则脚本的执行将被中止
Also, you should use set_time_limit, or execution of your script will be aborted