开发者

execute java program in the background while loading a page using php

I am trying to run a java program in the background using php. I am able to the run the program but the page doesn't load till java program completes executing.

I am able to run shell scripts in the background using php. But if i give the same command for java, it doesn't run in the background.

$command = "java hello";
$outputfile = "out1";
$pidfile = "out2";
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $开发者_StackOverflow社区command, $outputfile, $pidfile));

How can i run the program in the background?


I got this to work with the following:

shell_exec('java app.jar > /dev/null &');
exit();

Specifically I was trying to kick off a couple separate processes through a script in a TeamCity build step.


In the php docs for exec it says:

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.

so you need to change the output of the javafile to another terminal, not php or to a file maybe to /dev/null

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜