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

后端 未结 7 2041
暖寄归人
暖寄归人 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:52

    You basically want to signal the end of 1 process (return to the original Requester.php) and spawn a new process (finish Provider.php). There is probably a more elegant way to pull this off, but I've managed this a couple different ways. All of them basically result in exec-ing a command in order to shell off the second process.

    adding the following > /dev/null 2>&1 & to the end of your command will allow it to run in the background without inhibiting the actual execution of your current script

    Something like the following may work for you:

    exec("wget -O - \"$url\" > /dev/null 2>&1 &"); 
    

    -- though you could do it as a command line PHP process as well.

    You could also save the information that needs to be processed and handle the remaining processing on a cron job that re-creates the same sort of functionality without the need to exec.

提交回复
热议问题