Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 303
Nad Avatar asked Feb 05 '26 02:02

Nad


1 Answers

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.

like image 133
David Mårtensson Avatar answered Feb 06 '26 15:02

David Mårtensson