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)

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵