PHP exec(),我可以解雇然后忘记吗?

发布于 2024-10-16 13:21:54 字数 294 浏览 2 评论 0原文

我一直在尝试通过 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 技术交流群。

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

发布评论

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

评论(4

薆情海 2024-10-23 13:21:54

我认为这是同样的问题

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.

忆依然 2024-10-23 13:21:54

我也想在这里添加解决方案(感谢 ircmaxwell):

$shell = new COM("WScript.Shell");<br>
$shell->run($command, 0, false);

I would like to add the solution here as well (thanks to ircmaxwell):

$shell = new COM("WScript.Shell");<br>
$shell->run($command, 0, false);
放手` 2024-10-23 13:21:54

由于您在 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

吖咩 2024-10-23 13:21:54

在 MSWindows 上尝试:

exec("start java -jar c:\edu.uniroma3.jar c:\parameter2BPassed");

On MSWindows try:

exec("start java -jar c:\edu.uniroma3.jar c:\parameter2BPassed");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文