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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?