如何为 google api php 客户端库设置超时
How to set timeout for google api php client library
我正在使用 Google 的 php client library 构建应用程序。有时,Google 最多需要 100 秒来响应 API 请求。我想将套接字超时限制为 30 秒。
有人知道这怎么可能吗?在文档中没有看到任何明确的示例,我在查看源代码时没有发现与超时相关的内容。
我确实在 Java 客户端的文档中找到了 this example,但我似乎找不到 PHP 等价物。
感谢您的帮助。
根据this issue可以直接给curl传参数
$client->setClassConfig('Google_IO_Curl', 'options',
array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10
)
);
在 Google API v2 中,这可以通过 Guzzle 客户端完成
$http = $googleClient->getHttpClient();
$http->setDefaultOption('connect_timeout', 10);
$http->setDefaultOption('timeout', 10);
这个在 v2.2.2 上对我有用:
$client->setConfig('CURLOPT_CONNECTTIMEOUT', 100);
$client->setConfig('CURLOPT_TIMEOUT', 1000);
我正在使用 Google 的 php client library 构建应用程序。有时,Google 最多需要 100 秒来响应 API 请求。我想将套接字超时限制为 30 秒。
有人知道这怎么可能吗?在文档中没有看到任何明确的示例,我在查看源代码时没有发现与超时相关的内容。
我确实在 Java 客户端的文档中找到了 this example,但我似乎找不到 PHP 等价物。
感谢您的帮助。
根据this issue可以直接给curl传参数
$client->setClassConfig('Google_IO_Curl', 'options',
array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10
)
);
在 Google API v2 中,这可以通过 Guzzle 客户端完成
$http = $googleClient->getHttpClient();
$http->setDefaultOption('connect_timeout', 10);
$http->setDefaultOption('timeout', 10);
这个在 v2.2.2 上对我有用:
$client->setConfig('CURLOPT_CONNECTTIMEOUT', 100);
$client->setConfig('CURLOPT_TIMEOUT', 1000);