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

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

WBOY
Release: 2016-06-06 20:13:41
Original
1299 people have browsed it

<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>
Copy after login
Copy after login

回复内容:

<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>
Copy after login
Copy after login

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

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

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

start以后就不应该有代码了

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template