<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          AmpPHP 非阻塞并發(fā)框架

          聯(lián)合創(chuàng)作 · 2023-09-29 13:59

          Amp 是一個(gè) PHP 非阻塞并發(fā)框架,它提供了一個(gè)事件循環(huán),promise 和 stream 作為異步編程的基礎(chǔ)。與生成器結(jié)合使用的 promise 用于構(gòu)建協(xié)程,它允許像同步代碼一樣編寫(xiě)異步代碼,而不需要任何回調(diào)。

          demo:

          <?php
          
          use Amp\Artax\Response;
          use Amp\Loop;
          
          require __DIR__ . '/../vendor/autoload.php';
          
          Loop::run(function () {
              $uris = [
                  "https://google.com/",
                  "https://github.com/",
                  "https://stackoverflow.com/",
              ];
          
              $client = new Amp\Artax\DefaultClient;
              $client->setOption(Amp\Artax\Client::OP_DISCARD_BODY, true);
          
              try {
                  foreach ($uris as $uri) {
                      $promises[$uri] = $client->request($uri);
                  }
          
                  $responses = yield $promises;
          
                  foreach ($responses as $uri => $response) {
                      print $uri . " - " . $response->getStatus() . $response->getReason() . PHP_EOL;
                  }
              } catch (Amp\Artax\HttpException $error) {
                  // If something goes wrong Amp will throw the exception where the promise was yielded.
                  // The Client::request() method itself will never throw directly, but returns a promise.
                  print $error->getMessage() . PHP_EOL;
              }
          });
          瀏覽 20
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲激情综合视频 | 高清无码视频在线观看免费 | 免费视频在线观看一区 | 国产免费一区二区 | 乌克兰一级操逼片 |