开发者

How to run a PHP script asynchronously from a another PHP script? [duplicate]

开发者 https://www.devze.com 2023-02-13 09:25 出处:网络
This question already has answers here: 开发者_运维问答Closed 11 years ago. Possible Duplicate: Call another PHP script and return control to user before the other script completes
This question already has answers here: 开发者_运维问答 Closed 11 years ago.

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.


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";
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消