FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, integer given #234

Open brandfocus opened 9 years ago

brandfocus commented 9 years ago

We are receiving the following error with Goutte 3.1 and Guzzle 6.02 while setting curl options:

$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 60);

Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, integer given

fabpot/goutte (v3.1.0) guzzlehttp/promises (1.0.2) psr/http-message (1.0) guzzlehttp/psr7 (1.2.0) guzzlehttp/guzzle (6.0.2)

rustikov commented 9 years ago

Same here, $client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 60) breaks the code.

georaldc commented 9 years ago

The readme/doc is outdated and makes references to code not compatible with Guzzle 6. I don't think the setDefaultOption method exists anymore for that version of Guzzle so you might have to consult the latest Guzzle docs to find the equivalent call.

Last I checked, I couldn't find one though so you might have to instantiate a new Guzzle client with your desired settings and inject that into Goutte with the setClient method.

georaldc commented 9 years ago

Try this to have a 60 second timeout

$client = new \Goutte\Client();

// Create and use a guzzle client instance that will time out after 60 seconds
$guzzleClient = new \GuzzleHttp\Client(array(
    'timeout' => 60,
));
$client->setClient($guzzleClient);

Here's the related guzzle doc link about this setting: http://guzzle.readthedocs.org/en/latest/request-options.html#timeout

rustikov commented 9 years ago

@georaldc - it does not break the code any more, but takes no effect on timeout either. I still get the default timeout of 120 secs and fatal error of Maximum execution time of 120 seconds exceeded in \vendor\guzzlehttp\psr7\src\Stream.php on line 115

georaldc commented 9 years ago

@rustikov that looks more like a php execution time out error. I tested my example above just now and the timeout value passed is used just fine.

georaldc commented 9 years ago

To set curl options by the way, it looks like guzzle recognizes the key "curl" as a config setting, which takes in an array of curl-related config values. So the equivalent of what you were initially trying to achieve would look like the following

$client = new \Goutte\Client();

$guzzleClient = new \GuzzleHttp\Client(array(
    'curl' => array(
        CURLOPT_TIMEOUT => 60,
    ),
));
$client->setClient($guzzleClient);

Not sure how well this is supported since it isn't indicated anywhere in the guzzle docs (and doing it this way makes it look like its dependent on CURL, which I think is not the intention of guzzle. Hence the general timeout config entry). Might be better to ask about it there.

rustikov commented 9 years ago

Thanks for the help @georaldc. And yes, that was the php max execution time error, sorry.

nsanden commented 9 years ago

This helped me as well thanks!

oefada commented 8 years ago

This helped me as well. Thanks @georaldc!

diego1q2w commented 8 years ago

Thanks, this helped me as well, also works for SSL Certificate.

$guzzleClient = new \GuzzleHttp\Client(array( 'curl' => array( CURLOPT_SSL_VERIFYPEER => false, ), )); $client->setClient($guzzleClient);

aik099 commented 8 years ago

I hope you understand what security implications would be from disabling SSL certificate checks.

BafS commented 6 years ago

The setDefaultOption still break something in the code.