Php system () shell_exec () hangs in the browser

Possible duplicate:
Asynchronous exec shell in PHP

I need to run a java program in the background.

process.php contains

shell_exec("php php_cli.php")

php_cli.php contains

shell_exec("java -jar BiForce.jar settings.ini > log.txt");

I call process.php asynchronously using ajax

When I click on a link on a webpage that calls the ajax function (to run process.php), the webpage shows "loading". when I click other links, at the same time it is not responding.

It takes about 24 hours to complete the execution of the Java program, so the user will not wait for the execution to complete.

The problem is that the browser continues to load and does not go to other pages when the link is clicked.

I also tried with system (), but the same problem ....

Help would be greatly appreciated.

+3
4

, &:

shell_exec("java -jar BiForce.jar settings.ini > log.txt &");

, .

, ( ) process.php, php exec. include .

+1

shell_exec , , script.

, script .

PHP script , :

$processId = shell_exec(
    "nohup " .                          // Runs a command, ignoring hangup signals.
    "nice " .                           // "Adjusted niceness" :) Read nice --help
    "/usr/bin/php -c " .                // Path to your PHP executable.
    "/path/to/php.ini -f " .            // Path to your PHP config.
    "/var/www/php_cli.php " .           // Path to the script you want to execute.
    "action=generate > /process.log " . // Log file.
    "& echo $!"                         // Make sure it returns only the process id.
    );

, script :

exec('ps ' . $processId, $processState);
// exec returns the result of the command - but we need to store the process state.
// The third param is a referenced variable.

// First key in $processState is that it running.
// Second key would be that it has exited.
if (count($processState) < 2) {
    // Process has ended.
}
+5

, :

shell_exec("java -jar BiForce.jar settings.ini > log.txt &");

. exec PHP.

0

-, . , , , ...

, , PHP:

  • ajax ( ) (, )
    • ,
    • Java -
    • 24-

On the same idea, you can even use sockets instead of communicating with this Java program or in any other way.

The advantage is that a Java program that runs all the time, instead of starting a new process, should be able to reuse system resources throughout the life of the application; for example, if your program uses DB connections or any data, cache, etc.

0
source

All Articles