tags:

views:

27

answers:

1

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", $command, $outputfile, $pidfile));

How can i run the program in the background?

A: 

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

Logan Bailey