使用 Guzzle 发送多个请求时出现致命错误?

Getting fatal error on sending multiple requests with Guzzle?

这是我得到的错误

Argument 1 passed to GuzzleHttp\Client::send() must implement interface GuzzleHttp\Message\RequestInterface, array given,

这是我使用的代码

$guzzleResponses = $client->send(array(
$client->get('http://www.sitepoint.com/'),
$client->get('http://www.sitepoint.com/'),
$client->get('http://www.sitepoint.com/')
));

foreach($guzzleResponses as $guzzleResponse) {
$goutteObject = new Symfony\Component\BrowserKit\Response(
       $guzzleResponse->getBody(true), 
       $guzzleResponse->getStatusCode(), 
       $guzzleResponse->getHeaders()
);
}

我明白这个错误意味着我传递了一个数组,而它期望的是其他东西。但是我想同时处理多个请求,不能想别的办法吗?

这个问题已经(由您自己)提出并回答了 . To send multiple requests asynchronously you must use GuzzleHttp\Pool

您对 GuzzleHttp\Client->send() 的调用不正确。您实际上是在为它提供一组 ResponseInterfaces(不是预期的)。 GuzzleHttp\Client->get() 将在内部调用 $this->sent($this->createRequest('GET', $url, $options)),这意味着它将实际执行 http 请求和 return GuzzleHttp\Message\ResponseInterface 的实例。

根据其他几个具有相同需求的问题,新的 Guzzlehttp 包 guzzlehttp/guzzle 的答案可在 here 获得。按照 link 获取完整说明或查看下面的示例

参见示例此处

    $newClient = new  \GuzzleHttp\Client(['base_uri' => $base]);
    foreach($documents->documents as $doc){

        $params = [
            'language' =>'eng',
            'text' => $doc->summary,
            'apikey' => $key
        ];

        $requestArr[$doc->reference] = $newClient->getAsync( '/1/api/sync/analyze/v1?' . http_build_query( $params) );
    }

    $responses = \GuzzleHttp\Promise\unwrap($requestArr); //$newClient->send( $requestArr );