如何在Google API PHP客户端版本2.2.2中设置curl超时 [英] How to set curl timeout in Google API PHP client version 2.2.2

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

问题描述

我正在尝试在用于使用目录api批量更新用户的脚本中设置默认的curl超时.在curl连接超时之前,仅添加了少数用户.

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.

我已经对此进行了尝试,但是它不适用于API v2.2.2

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

有人可以告诉我如何使用php更新curl超时设置吗?

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

谢谢.

这是代码:

$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";
}

推荐答案

尝试一下:

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

请记住,可能的问题可能在于最大执行时间(如果我记得3到5分钟之间的某个时间)

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)

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

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