2017-07-06 110 views
0

我使用狂飲異步池,但它似乎文檔中我該如何使用池來獲取收益缺失的部分?狂飲得到結果,對池

按照文檔:

$client = new Client(); 

$requests = function ($total) use ($client) { 
    $uri = 'http://localhost/'; 
    for ($i = 0; $i < $total; $i++) { 
     yield function() use ($client, $uri) { 
      return $client->requestAsync($uri); 
     }; 
    } 
}; 

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

我如何使用$pool消耗所有的回答嗎?

回答

0

使用該Pool::batch()方法。還考慮限制併發性以避免一次發出100個請求...

$responses = Pool::batch(
    $client, 
    $requests(100), 
    ['concurrency' => 5] 
);