只是查看 Goutte 的代码,快速显示它不支持多个请求。
但是,如果您愿意,您可以通过收集 Guzzle 请求并创建一个新的Symfony\Component\BrowserKit\Response对象来模仿 Goutte,这是 Goutte 返回以供用户交互的对象。
查看他们的 createResponse() 函数(不幸的是,它受到保护)以获取更多信息。
<?php
// Guzzle returns an array of Responses.
$guzzleResponses = $client->send(array(
$client->get('http://www.example.com/foo'),
$client->get('http://www.example.com/baz'),
$client->get('http://www.example.com/bar')
));
// Iterate through all of the guzzle responses.
foreach($guzzleResponses as $guzzleResponse) {
$goutteObject = new Symfony\Component\BrowserKit\Response(
$guzzleResponse->getBody(true),
$guzzleResponse->getStatusCode(),
$guzzleResponse->getHeaders()
);
// Do things with $goutteObject as you normally would.
}
请注意,当您等待在$guzzleResponses中收集响应时,它将等待所有异步完成。如果您想立即响应,请查看Guzzle 文档以处理异步请求。