Reputation: 259
This is the error I get
Argument 1 passed to GuzzleHttp\Client::send() must implement interface GuzzleHttp\Message\RequestInterface, array given,
and this is the code I am using
$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()
);
}
I understand the error means I am passing an array when it expected something else. But I want to process multiple requests simultaneously and unable ot think any other way?
Upvotes: 0
Views: 3588
Reputation: 1872
As per several other questions with the same need an answer with the new Guzzlehttp package guzzlehttp/guzzle is available at here . Follow the link for a full description or look at the example below
See example here
$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 );
Upvotes: 1
Reputation: 2047
This question was already asked (by yourself) and answered here. To send multiple requests asynchronously you must use GuzzleHttp\Pool
Your call to GuzzleHttp\Client->send()
is incorrect. You are actually feeding it an array of ResponseInterfaces (not what is intended).
The GuzzleHttp\Client->get()
will internally call $this->sent($this->createRequest('GET', $url, $options))
which means that it will actually perform the http request and return an instance of GuzzleHttp\Message\ResponseInterface
.
Upvotes: 3