PHP exec(),我可以解雇然后忘记吗?
我一直在尝试通过 php 表单执行 java 应用程序..因此提交按钮会触发执行命令:
exec("java -jar c:\edu.uniroma3.jar c:\parameter2BPassed");
第一个路径确定 jar 文件的位置,第二个路径用作参数。
问题是脚本处理时间太长,我想绕过等待,有没有办法做到这一点(比如一劳永逸)?该脚本将结果写入文件,我可以每 5 分钟检查一次文件是否存在,但等待过程完成很不方便...
有什么建议吗?
先感谢您
I have been trying to execute a java application through a php form .. so the submit button fire an execute command:
exec("java -jar c:\edu.uniroma3.jar c:\parameter2BPassed");
The first path determines where the jar file is, the 2nd one serves as a parameter.
The problem is that the script takes too long to be processed and I would like to bypass the waiting, is there anyway to do it (like a fire and forget)? The script writes results into a file, and I can check every 5 minutes if the file is there, but it's inconvenient getting stuck waiting for the process to finish...
any suggestions ?
thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这是同样的问题
Asynchronous shell exec in PHP
正如评论指出上述作品仅在 *nix 环境中,但我发现与 Windows 类似:
http://www.somacon.com /p395.php
不过,最好考虑其他解决方案,例如一个单独的进程,您可以将工作发送到未连接到网络服务器的进程。
据我所读,网络服务器有时回收进程和后台进程并不总是隔离的,因此您可能会杀死外部进程,除非它完全独立。
I think this is the same problem
Asynchronous shell exec in PHP
As comments note the above works only in *nix environment but I found a similar to this for windows:
http://www.somacon.com/p395.php
Still, it might be better to think about other solutions like a separate process which you can send work to that is not connected to the webserver.
Webservers sometimes recycle processes and background processes are not always isolated as far as I have read so you might have your external process killed unless it is completly separate.
我也想在这里添加解决方案(感谢 ircmaxwell):
I would like to add the solution here as well (thanks to ircmaxwell):
由于您在 Windows 上并且需要启动 java 程序,因此可以使用 javaw.exe 而不是 java.exe。
Windows 上的 javaw 旨在启动 jvm,而无需打开 cmd 窗口。
也许有帮助
Since you are on windows and you need to start a java program, you can use the javaw.exe instead of java.exe.
javaw on windows, is designed to start a jvm without open a cmd window.
Maybe it could help
在 MSWindows 上尝试:
On MSWindows try: