[英]How to set curl timeout in Google API PHP client version 2.2.2
我正在嘗試在我用於使用目錄 api 批量更新用戶的腳本中設置默認 curl 超時。 在 curl 連接超時之前只添加了少數用戶。
我試過了,但它不適用於 API v2.2.2
有人可以告訴我如何使用 php 更新 curl 超時設置嗎?
謝謝你。
這是代碼:
$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 分鍾之間的事情)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.