How to use named pipes in PHP between different functions or even different processes without fork?

后端 未结 3 1515
一向
一向 2021-01-13 14:34

I want to write an Ajax web application, a game to be specific. Two web clients have to communicate with each other via the PHP server. My approach to solve this is to use A

3条回答
  •  太阳男子
    2021-01-13 15:14

    When you use the pipes in separate functions like this, the write pipe A would seem to be closed/discarded again (local scope of $pipeA). The assumption would be that the pipe must be opened for reading and/or writing in order to retain any info, which makes sense really. Though I don't know the inner magic.

    You can also observe that your blocking read-call succeeds when you feed the pipe from another process (like echo magic >> testpipe). So you'd already have step 2 done, but you need some pipehandle management.

    If you change it as follows it'd work:

        private $pipeA;
        public function writePipe_test(){
            $this->pipeA = fopen("testpipe",'r+');
            fwrite($this->pipeA, 'ABCD');
        }
    

    Edit: or setting $pipeA to have global scope, for that matter..

提交回复
热议问题