PHP: How to return information to a waiting script and continue processing

后端 未结 7 2052
暖寄归人
暖寄归人 2021-02-09 22:14

Suppose there are two scripts Requester.php and Provider.php, and Requester requires processing from Provider and makes an http request to it (Provider.php?data=\"data\"). In th

7条回答
  •  悲哀的现实
    2021-02-09 22:37

    You could start another php process in Provider.php using pcntl_fork()

    Provider.php 
    {
        // Fork process
        $pid = pcntl_fork();
    
        // You are now running both a daemon process and the parent process
        // through the rest of the code below
    
        if ($pid > 0) {
            // PARENT Process
            $answer = getAnswer($_GET['data']);
            echo $answer;    
            //SIGNAL TO REQUESTER THAT WE ARE FINISHED
            return;
        }
    
        if ($pid == 0) {
            // DAEMON Process
            processDBUpdates();
            return;
        }
    
        // If you get here the daemon process failed to start
        handleDaemonErrorCondition();
        return;
    
    }
    

提交回复
热议问题