Search code examples
phpgoogle-apigoogle-api-php-clientgmail-api

How to set timeout for google api php client library


I am using Google's php client library to build an app. Sometimes, Google takes up to 100 seconds to respond to an API request. I'd like to limit the socket timeout to 30 seconds.

Anyone know how this is possible? Not seeing any clear examples in the docs and I nothing timeout-related jumped out at me looking at the source.

I did find this example in the docs for the Java client, but I can't seem to find the PHP equivalent.

Thanks for any help.


Solution

  • According to this issue you can pass parameters directly to curl.

    $client->setClassConfig('Google_IO_Curl', 'options',
        array(
            CURLOPT_CONNECTTIMEOUT => 10,
            CURLOPT_TIMEOUT => 10
        )
    );