在循环内执行外部php文件

发布于 2024-12-15 12:12:54 字数 189 浏览 3 评论 0原文

如果我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

滥情稳全场 2024-12-22 12:12:54

系统执行命令,然后挂起,直到命令执行完毕。

<前><代码>注意:

如果程序使用此函数启动,为了使其继续在后台运行,>程序的输出必须重定向到文件或另一个输出流。如果不这样做将导致 PHP 挂起,直到程序执行结束。

来自手册: http://php.net/manual/en/function.system.php

System executes the command and then hangs until the command is executed.

Note:

If a program is started with this function, in order for it to continue running in the background, the output of >the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the >execution of the program ends.

From the manual: http://php.net/manual/en/function.system.php

与君绝 2024-12-22 12:12:54

一旦 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.

心是晴朗的。 2024-12-22 12:12:54

如果brunoais和Sabeen Malik的方式不起作用,请一起尝试:

system("command > /dev/null &")

在Windows下我认为你可以使用启动命令:

system("start command")

If brunoais and Sabeen Malik way does not work, try both together:

system("command > /dev/null &")

Under windows I think you can use the start command:

system("start command")
笑,眼淚并存 2024-12-22 12:12:54

另外,您应该使用 set_time_limit,否则脚本的执行将被中止

Also, you should use set_time_limit, or execution of your script will be aborted

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文