如何为Google API PHP客户端库设置超时 [英] How to set timeout for google api php client library

查看:86
本文介绍了如何为Google API PHP客户端库设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google的 php客户端库来构建应用.有时,Google最多需要100秒才能响应API请求.我想将套接字超时限制为30秒.

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.

我确实找到了此示例在Java客户端的文档中,但我似乎找不到等效的PHP.

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

感谢您的帮助.

推荐答案

根据

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

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

这篇关于如何为Google API PHP客户端库设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆