PHP exec(), can I fire and forget?

3.3k views Asked by At

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

4

There are 4 answers

4
David MÃ¥rtensson On

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.

1
symcbean On

On MSWindows try:

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

i would like to add the solution here aswell:
$shell = new COM("WScript.Shell");
$shell->run($command, 0, false);

worked like magic :) thx alot ircmaxell

0
Francesco Laurita On

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