<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 2.0.5 [TOC] Swoole 2.0正式版發布了。2.0版本最大的更新是增加了對協程(Coroutine)的支持。正式版已同時支持PHP5和PHP7。基于Swoole2.0協程PHP開發者可以已同步的方式編寫代碼,底層自動進行協程調度,轉變為異步IO。解決了傳統異步編程嵌套回調的問題。 與Node.js(ES6+)、Python等語言使用yield/generator、async/await的實現方式相比,Swoole協程無需修改代碼添加額外的關鍵詞。 與Go語言的goroutine相比,Swoole協程是內置式的,應用層代碼無需添加go關鍵詞啟動協程,只需要使用封裝好的協程客戶端即可,使用更簡單。另外Swoole協程的IO組件在底層內置了超時機制,不需要使用復雜的select/chan/timer實現客戶端超時。 目前Swoole底層內置的協程客戶端組件包括:udpclient、tcpclient、httpclient、redisclient、mysqlclient,基本涵蓋了開發者常用的幾種通信協議。協程組件只能在服務器的onConnect、onRequest、onReceive、onMessage 回調函數中使用。 ## 使用示例 ~~~ $server = new Swoole\Http\Server('127.0.0.1', 9501); /* 觸發on request事件時,SWOOLE會開辟一個協程棧,對協程棧進行初始化 */ $server->on('Request', function ($request, $response) { $tcp_cli = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP); /** client在調用connect函數后,SWOOLE會將PHP上下文信息保存到當前棧內 然后將協程掛起,待確認連接成功后,觸發epoll事件,然后協程切換 恢復PHP上下文信息,返回結果,繼續執行PHP代碼 */ if ($tcp_cli->connect('127.0.0.1', 9906) === false) { $response->end("connect server failed."); return; } $tcp_cli->send('test for the coro'); /* client在調用recv函數后,SWOOLE會將PHP上下文信息保存到當前棧內 然后將協程掛起待后端svr回包,觸發epoll事件,然后協程切換 恢復PHP上下文信息,返回結果,繼續執行PHP代碼 如果后端在設定的超時時間內,未能回包,返回false client的errCode定為110 */ $ret = $tcp_cli->recv(100); $tcp_cli->close(); if ($ret) { $response->end(" swoole response is ok"); } else { $response->end(" recv failed error : {$tcp_cli->errCode}"); } }); $server->start(); ~~~ ## UDP客戶端 ~~~ $udp_cli = new Swoole\Coroutine\Client(SWOOLE_SOCK_UDP); $ret = $udp_cli->connect('127.0.0.1', 9906); $udp_cli->send('test for the coro'); $ret = $udp_cli->recv(100); $udp_cli->close(); if ($ret) { $response->end("swoole response is ok"); } else { $response->end("recv failed error : {$client->errCode}"); } ~~~ ## MySQL客戶端 ~~~ $swoole_mysql = new Swoole\Coroutine\MySQL(); $swoole_mysql->connect([ 'host' => '127.0.0.1', 'user' => 'user', 'password' => 'pass', 'database' => 'test' ]); $res = $swoole_mysql->query('select sleep(1)'); Redis客戶端 $redis = new Swoole\Coroutine\Redis(); $redis->connect('127.0.0.1', 6379); $val = $redis->get('key'); ~~~ ## Http客戶端 ~~~ $cli = new Swoole\Coroutine\Http\Client('127.0.0.1', 80); $cli->setHeaders([ 'Host' => "localhost", "User-Agent" => 'Chrome/49.0.2587.3', 'Accept' => 'text/html,application/xhtml+xml,application/xml', 'Accept-Encoding' => 'gzip', ]); $cli->set([ 'timeout' => 1]); $cli->get('/index.php'); echo $cli->body; $cli->close(); ~~~ ## 下載地址: * Github:[https://github.com/swoole/swoole-src/releases/tag/v2.0.5](https://github.com/swoole/swoole-src/releases/tag/v2.0.5) * 開源中國:[http://git.oschina.net/matyhtf/swoole/tree/v2.0.5](http://git.oschina.net/matyhtf/swoole/tree/v2.0.5) * PECL:[https://pecl.php.net/package/swoole/2.0.5](https://pecl.php.net/package/swoole/2.0.5)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看