Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用goutte同步HTTP请求_Php_Http_Curl_Guzzle_Goutte - Fatal编程技术网

Php 使用goutte同步HTTP请求

Php 使用goutte同步HTTP请求,php,http,curl,guzzle,goutte,Php,Http,Curl,Guzzle,Goutte,我知道这是建立在你的基础之上的。使用guzzle同时执行HTTP请求 <?php $client->send(array( $client->get('http://www.example.com/foo'), $client->get('http://www.example.com/baz'), $client->get('http://www.example.com/bar') )); 只要快速查看Goutte的代码,就会发现它不支持多

我知道这是建立在你的基础之上的。使用guzzle同时执行HTTP请求

<?php
$client->send(array(
    $client->get('http://www.example.com/foo'),
    $client->get('http://www.example.com/baz'),
    $client->get('http://www.example.com/bar')
));

只要快速查看Goutte的代码,就会发现它不支持多个请求

但是,如果您愿意,可以通过收集Guzzle请求并创建一个新的Symfony\Component\BrowserKit\Response对象来模拟Goutte,Goutte将返回该对象供用户交互

(不幸受到保护)以获取更多信息

<?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.
}

谢谢你,艾凡!在这件事上我完全同意你,我自己也开始攻击古特。不过,我所做的改变略有不同。我已经在goutte客户端和BrowserKit客户端中添加了一个
doRequestMulti
(还没有时间测试!)。很明显,一些功能将丢失(对cookie、“隔离”、重定向和历史记录的支持),但它可能适用于我的用例,因为我不想爬过任何这些多请求页面。让我做一点测试,然后和你一起返回。@quickshiftin是的,Goutte在执行请求时提供的一些功能丢失了,但它为返回的内容提供了一些遍历功能。(在这种情况下使痛风无效)将它们都称为单独的过程?