Home >Backend Development >PHP Tutorial >php swoole 如何不让代码停在start()这里?

php swoole 如何不让代码停在start()这里?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:13:411327browse

<code>        $serv = new swoole_server($address, $port, SWOOLE_BASE, SWOOLE_SOCK_TCP);
        $serv->on('Connect',
            function (){
              echo "!!!!!";
            }
        );
        $serv->on('Receive',
            function (){
                echo "!!!!!";
            }
        );
        $serv->on('Close',
            function (){
                echo "!!!!!";
            }
        );
        echo "?????";
        $serv->start();#停在这里
        echo "?????";#打不出来,我还想干别的,只想让这个server在一个线程里监听着</code>

回复内容:

<code>        $serv = new swoole_server($address, $port, SWOOLE_BASE, SWOOLE_SOCK_TCP);
        $serv->on('Connect',
            function (){
              echo "!!!!!";
            }
        );
        $serv->on('Receive',
            function (){
                echo "!!!!!";
            }
        );
        $serv->on('Close',
            function (){
                echo "!!!!!";
            }
        );
        echo "?????";
        $serv->start();#停在这里
        echo "?????";#打不出来,我还想干别的,只想让这个server在一个线程里监听着</code>

开一个子进程去启动server就好了

官网有例子 在子进程中创建swoole_server

因为 start 里面已经开始事件循环了。你可以理解为这里面是死循环。

start以后就不应该有代码了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn