Nad
Nad

Reputation: 83

PHP exec(), can I fire and forget?

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

Upvotes: 3

Views: 3436

Answers (4)

Nad
Nad

Reputation: 83

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

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

Upvotes: 1

Francesco Laurita
Francesco Laurita

Reputation: 23552

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

Upvotes: 0

David M&#229;rtensson
David M&#229;rtensson

Reputation: 7600

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.

Upvotes: 1

symcbean
symcbean

Reputation: 48357

On MSWindows try:

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

Upvotes: -1

Related Questions