Can a PHP script start another PHP script and exit?

前端 未结 6 1915
长发绾君心
长发绾君心 2021-02-04 17:02

How can a PHP script start another PHP script, and then exit, leaving the other script running?

Also, is there any way for the 2nd script to inform the PHP script when i

6条回答
  •  广开言路
    2021-02-04 17:42

    If you don't want to build the pcntl extension, then a good alternative is to use proc_open().

    http://www.php.net/manual/en/function.proc-open.php

    Use that together with stream_select() so your PHP process can sleep until something happens with the child process you created.

    That will effectively create a process in the background, without blocking the parent PHP process. You PHP can read and write to STDIN, STDOUT, STDERR.

    To make the browser complete loading (stop the load progress indicator) then you can use what Milan Babuškov mentioned.

    The key to making the browser think the HTTP request is complete, is to send it the content length. To do this you can start buffering the request, then flush it after you send the Content-Length header.

    eg:

    
    

提交回复
热议问题