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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流