第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 id 添加到 Guzzle 請求

將 id 添加到 Guzzle 請求

PHP
狐的傳說 2022-12-03 10:42:40
如何向池中發(fā)送的 guzzle 請求添加一些元數(shù)據(jù)?我需要為請求添加 id 以確定將哪個請求分配給響應(yīng)。我想要這樣的東西 - 將 id 設(shè)置為請求并從響應(yīng)中獲取它。將 id 設(shè)置為 Header 似乎不是個好主意。請幫忙。    $requests = function ($total) {    $uri = 'http://127.0.0.1:8126/guzzle-server/perf';    for ($i = 0; $i < $total; $i++) {         $myAdditionalId = $i;        yield new Request('GET', $uri, $myAdditionalId);    }};    $pool = new Pool($client, $requests(100), [        'concurrency' => 5,        'fulfilled' => function (Response $response, $index) {             echo $response->getMyAdditionalId();            // this is delivered each successful response        },        'rejected' => function (RequestException $reason, $index) {            // this is delivered each failed request        },]);
查看完整描述

1 回答

?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個贊

我以這種方式解決這個問題:


$requests = function ($total) {

    $uri = 'http://127.0.0.1:8126/guzzle-server/perf';

    for ($i = 0; $i < $total; $i++) {

         $myAdditionalId = $i;

            $promise =  $client->getAsync($uri);

         $promise->then(function () use ($myAdditionalId){

         //add callback with function on success

         echo $myAdditionalId;

          });

        yield function()use($promise){return $promise;};

    }

};


    $pool = new Pool($client, $requests(100), [

        'concurrency' => 5,

        'rejected' => function (RequestException $reason, $index) {

            // this is delivered each failed request

        },


]);


查看完整回答
反對 回復(fù) 2022-12-03
  • 1 回答
  • 0 關(guān)注
  • 93 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號