php system() shell_exec() 挂起浏览器
可能的重复:
PHP 中的异步 shell 执行
我需要在后台运行一个 java 程序。
process.php 包含
shell_exec("php php_cli.php")
php_cli.php 包含
shell_exec("java -jar BiForce.jar settings.ini > log.txt");
我正在使用 ajax 异步调用 process.php
当我单击网页中调用 ajax 函数的链接时(用于运行 process.php) php) 网页显示“正在加载”。当我同时单击其他链接时,它没有响应。
java程序大约需要24小时才能执行完毕,因此用户不会等到执行结束。
问题在于,单击链接时浏览器会继续加载并且不会转到其他页面。
我也尝试过使用 system(),但同样的问题......
我们将不胜感激。
Possible Duplicate:
Asynchronous shell exec in PHP
i need to run a java program in the background.
process.php contains
shell_exec("php php_cli.php")
php_cli.php contains
shell_exec("java -jar BiForce.jar settings.ini > log.txt");
I am calling process.php asynchronously using ajax
When i click the link in the webpage that calls ajax function (for running process.php) the webage shows "loading". when i click other links at the same time it does not responds.
The java program takes about 24 hours to finish executing, so user will not wait until the execution ends.
The problem is that the browser keeps on loading and does not go to other pages when clicked the link.
I also tried with system(), but the same problem ....
Help will greatly be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 shell_exec 等待命令挂起,这就是您的脚本正在做的事情。
如果您的命令没有任何等待时间,那么您的脚本也不会。
您可以从原始脚本调用另一个 PHP 脚本,而无需等待它挂起:
然后可以使用以下命令检测脚本是否完成:
Using
shell_exec
waits for the command to hang up, so that's what your script is doing.If your command doesn't have any wait time, then your script will not either.
You can call another PHP script from your original, without waiting for it to hang up:
It is then possible to detect whether or not the script is finished by using this command:
您可以在显示的页面中调用该命令,但在末尾附加 &:
这样该进程就会在后台启动。
另外,不需要(除非由您的应用程序定义)创建一个 process.php ,它本身通过 shell exec 调用 php。您可以通过包含到另一个文件来归档相同的功能。
You could call the command in the page displayed, but appending an & at the end:
This way the process is launched on the background.
Also, there is no need (unless defined by your application) to create a process.php wich itself calls php via a shell exec. You could archive the same functionality via an include to the other file.
与普通 shell 脚本一样,您可以使用 & 符号来后台处理进程:
请参阅 PHP 中的异步 shell 执行< /a> .
As in normal shell scripting you can use the ampersand to background the process:
See Asynchronous shell exec in PHP .
首先,您可能想要重新设计这个概念。我不确定这些程序到底做了什么,但显然这可能会导致潜在的问题...
这就是我建议你做的,而不是通过 PHP 启动外部进程:
。甚至可以使用套接字或任何其他方式与该 Java 程序进行通信。
让Java程序一直运行而不是启动一个新进程的优点是能够在应用程序的生命周期内重用系统资源;例如,如果您的程序正在使用数据库连接,或任何数据、缓存等。
First, you might want to redesign this concept. I am not sure exactly what these programs do, but clearly this is can lead to potential problems...
This is what I suggest you do, instead of starting external processes via PHP:
Along the same idea, you can even use sockets instead to communicate with that Java program, or any other way.
The advantage of having the Java program running all the time instead of starting a new process is to be able to reuse system resources within the lifetime of the application; for example, if your program is using DB connections, or any data, cache, etc.