duanshang3230 2019-03-05 08:43 采纳率: 100%
浏览 59
已采纳

如何在Google API PHP客户端版本2.2.2中设置卷曲超时

I am trying to set the default curl timeout in the scripts I am using for batch updating users using directory api. Only a handful of users are added before the curl connection times out.

I have tried this but it doesn't work with the API v2.2.2

Can someone show me how to update the curl timeout settings using php?

Thank you.

Here is the code:

$groupEmail = "my group email";

require_once realpath(dirname(__FILE__).'/vendor/autoload.php');
$client = new Google_Client();
$client->setAuthConfig('my-config.json');
$client->useApplicationDefaultCredentials();
$client->setScopes(array('https://www.googleapis.com/auth/admin.directory.user.readonly', 
'https://www.googleapis.com/auth/admin.directory.group'));
$client->setSubject('user being impersonated');
$service = new Google_Service_Directory($client); 

try {
    //try something

    for($i=1;$i<=1000;$i++)
    {
        $addThese[] = "something".$i."@gmail.com";
    }   

    //EXECUTE ADDITIONS AND REMOVEALS
    $client->setUseBatch(true);
    $batch = new Google_Http_Batch($client);

    foreach($addThese as $addThis)
    {
        $member = new Google_Service_Directory_Member(array('email' => $addThis,
                                'kind' => 'admin#directory#member',
                                'role' => 'MEMBER',
                                'type' => 'USER'));
        $batch->add($service->members->insert($groupEmail, $member));
    }
    $result = $batch->execute();

} catch (Exception $e) {
    // do something about the error
    //echo "Error: $e";
}
  • 写回答

1条回答 默认 最新

  • drl47263 2019-03-05 09:45
    关注

    Try this:

    $client->setConfig('CURLOPT_CONNECTTIMEOUT', 100);
    $client->setConfig('CURLOPT_TIMEOUT', 1000);
    

    have in mind that possible problem can be in their max execution time (which is if i good remember something between 3 and 5 mins)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站