Search code examples
phpfunctionbackgroundcross-platformexecution

PHP functions to execute a script in background?


I have bunch of PHP Scripts that require execution on press of a button in an HTML web page. I have browsed through various PHP functions which could do that, however I am confused as to which of these functions listed on PHP Manual will work best in my situation.

http://www.php.net/manual/en/ref.exec.php

In total there are following four buttons on a single web page linking to their respective scripts.

  1. Archive ==> archive.php // takes few minutes.
  2. Download ==> download.php // takes 3 to 6 hours.
  3. Format ==> format.php // takes few seconds.
  4. Update ==> update.php // takes few minutes

Also, which of these functions are cross platform?


Solution

  • I am using 'system', and it works correctly.

    $last_line = system('ls', $retval);
        echo "<br>";
        echo "the last line of the output: ". $last_line;
        echo "<br>";
        echo "Return value: ".$retval;
    

    Just replace 'ls' with your command, like "php text.php".

    Good luck.