Can a PHP script start another PHP script and exit?

前端 未结 6 1899
长发绾君心
长发绾君心 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:29

    You can effectively achieve this by forking and then calling include or require.

    parent.php:

    
    

    sleeper.php:

      
    

    Output:

    $ php parent.php
    Sleeper started at 01:22:02
    Parent waiting at 01:22:02
    Sleeper done at 01:22:05
    Parent done at 01:22:05
    

    However, forking does not inherently allow any inter-process communication, so you'd have to find some other way to inform the parent that the child has reached the specific line, like you asked in the question.

提交回复
热议问题