<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>

                ### 實戰:實現waitGroup功能 利用Swoole提供的Channel實現一個 waitGroup ,主要功能是用來等待所有協程執行完成的。 ```php <?php class WaitGroup{ private $count; private $chan; public function __construct() { $this->chan = new Swoole\Coroutine\Channel(); } public function add(){ $this->count++; } public function done(){ $this->chan->push(true); } public function wait(){ for($i=0;$i<$this->count;$i++){ $this->chan->pop(); } } } <?php include 'waitgroup.php'; Swoole\Runtime::enableCoroutine(true); echo "start".PHP_EOL; $t = microtime(true); go(function() use ($t){ $wg = new WaitGroup(); $wg->add(); go(function() use ($t,&$wg){ echo file_get_contents("https://www.sunnyos.com/swoole.php"); echo "協程1:".(microtime(true)-$t).PHP_EOL; $wg->done(); }); $wg->add(); go(function() use ($t,&$wg){ echo file_get_contents("https://www.sunnyos.com/swoole.php"); echo "協程2:".(microtime(true)-$t).PHP_EOL; $wg->done(); }); $wg->add(); go(function() use ($t,&$wg){ echo file_get_contents("https://www.sunnyos.com/swoole.php"); echo "協程3:".(microtime(true)-$t).PHP_EOL; $wg->done(); }); $wg->wait(); echo '全部結束:'.(microtime(true)-$t).PHP_EOL; }); echo "end".PHP_EOL; echo microtime(true)-$t.PHP_EOL; ```
                  <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>

                              哎呀哎呀视频在线观看