2

Possible Duplicate:
Call another PHP script and return control to user before the other script completes

I need to run a PHP script from another PHP script asynchronously.


Script 1

<?php
    echo "Entering main script 1";
    system("php script2.php");
    echo "Exiting main script 1";
?>

Script 2

<?php
    echo "Entering script 2";
    sleep(10);
    echo "Exiting script 2";
?>

In script 1, I use system() method to run script2.php. I dont want script 1 to wait for script 2 to complete its execution. How to make it asynchronous? Is there any other method to run a PHP script without using system() function? Please help me. Thanks.

3
  • 4
    Duplicate of this thread : stackoverflow.com/questions/5103528 You can use the same solution I provided Commented Feb 26, 2011 at 15:11
  • @JohnP: That did't work for me! can you give me an example. Commented Feb 26, 2011 at 15:48
  • 1
    What was the problem, any error message? Keep in mind you need to send the output of the script to a file (or any other output stream) using the $output and $return_var params. Simply opening up a file descriptor with fopen and passing that should do it. Commented Feb 26, 2011 at 16:09

1 Answer 1

5

Add an & to the end of the command-line to make the process run in the background on the vast majority of shells. i.e.:

Script 1

<?php
    echo "Entering main script 1";
    system("php script2.php &");
    echo "Exiting main script 1";
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.