2

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

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
Nad
  • 63
  • 1
  • 6
  • maybe try system() instead of exec() ? not sure if itll work the way you want it.. in linux you can just put a process in background.. in windows... well... a bit more work – Sigtran Feb 08 '11 at 12:06
  • 2
    possible duplicate of [nohup on windows, exec without waiting for finish - PHP](http://stackoverflow.com/questions/4197579/nohup-on-windows-exec-without-waiting-for-finish-php) – ircmaxell Feb 08 '11 at 12:13
  • OK .. problem solved thanks to ircmaxell, it was a duplicate post, sorry for that but it is really hard to find that post when you use the wrong keywords, anyway; what should i do with this post ? delete ? – Nad Feb 08 '11 at 12:19
  • i would like to add the solution here aswell: – Nad Feb 08 '11 at 12:29
  • I would suggest that you delete the question to prevent clutter on the site (since it really is a duplicate). Otherwise the answer pool gets diluted and makes searching return fewer results rather than more... – ircmaxell Feb 08 '11 at 13:54

4 Answers4

1

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.

Community
  • 1
  • 1
David Mårtensson
  • 7,550
  • 4
  • 31
  • 47
  • i am afraid it's a quite different .. i tried this one exec("java -jar C:\edu.uniroma3.lexmeter.jar ".$XMLFileLoc. " /dev/null 2>/dev/null &"); but it didnt even execute – Nad Feb 08 '11 at 12:09
  • this one is done in linux :) the problem above is on a windows based machine @Nad you have windows, /dev/null doesnt exist there :) – Sigtran Feb 08 '11 at 12:09
  • It's also very, *very* wrong - it will appear to work sometimes but it will break your application in weird and wonderful ways. This is **not** how to run a background process from a web request. – symcbean Feb 08 '11 at 12:16
  • @symcbean - What is the better/best way to run a bg process? – Hans Feb 08 '11 at 12:17
0

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

Nad
  • 63
  • 1
  • 6
0

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

Francesco Laurita
  • 23,434
  • 8
  • 55
  • 63
-1

On MSWindows try:

exec("start java -jar c:\edu.uniroma3.jar c:\parameter2BPassed");
symcbean
  • 47,736
  • 6
  • 59
  • 94