หมดเวลา
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
บริการทั้งหมดของ Google Ads API มีการตั้งค่าเริ่มต้น รวมถึงการหมดเวลาที่ใช้โดยการรับส่ง บริการใดก็ตามของ Google Ads API เวอร์ชันที่กำหนดจะมีไฟล์ JSON เฉพาะที่มีการกำหนดการตั้งค่าเริ่มต้นเหล่านี้ที่ระดับบริการและเมธอด เช่น คุณดูไฟล์ที่เกี่ยวข้องกับ Google Ads API
เวอร์ชัน
ล่าสุดได้ที่นี่
การตั้งค่าเริ่มต้นเพียงพอสำหรับกรณีการใช้งานส่วนใหญ่ แต่บางครั้งคุณอาจต้องลบล้างการตั้งค่าเหล่านั้น ไลบรารีของไคลเอ็นต์สำหรับ PHP รองรับการลบล้าง
การตั้งค่าการหมดเวลาสำหรับการสตรีมฝั่งเซิร์ฟเวอร์และการเรียกแบบเอกภาคทั้ง 2 แบบ
คุณตั้งค่าการหมดเวลาเป็น 2 ชั่วโมงขึ้นไปได้ แต่ API อาจยังคงหมดเวลาสำหรับคำขอที่ใช้เวลานานมากและแสดงข้อผิดพลาด DEADLINE_EXCEEDED
การลบล้างระยะหมดเวลาสำหรับการเรียกสตรีมมิงของเซิร์ฟเวอร์
เมธอดบริการ Google Ads API เพียงเมธอดเดียวที่ใช้การเรียกประเภทนี้คือ
GoogleAdsService.SearchStream
หากต้องการลบล้างระยะหมดเวลาเริ่มต้น คุณต้องเพิ่มพารามิเตอร์พิเศษเมื่อเรียกใช้เมธอด
private static function makeServerStreamingCall(
GoogleAdsClient $googleAdsClient,
int $customerId
) {
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
// Creates a query that retrieves all campaign IDs.
$query = 'SELECT campaign.id FROM campaign';
$output = '';
try {
// Issues a search stream request by setting a custom client timeout.
/** @var GoogleAdsServerStreamDecorator $stream */
$stream = $googleAdsServiceClient->searchStream(
SearchGoogleAdsStreamRequest::build($customerId, $query),
[
// Any server streaming call has a default timeout setting. For this
// particular call, the default setting can be found in the following file:
// https://github.com/googleads/google-ads-php/blob/master/src/Google/Ads/GoogleAds/V21/Services/resources/google_ads_service_client_config.json.
//
// When making a server streaming call, an optional argument is provided and can
// be used to override the default timeout setting with a given value.
'timeoutMillis' => self::CLIENT_TIMEOUT_MILLIS
]
);
// Iterates over all rows in all messages and collects the campaign IDs.
foreach ($stream->iterateAllElements() as $googleAdsRow) {
/** @var GoogleAdsRow $googleAdsRow */
$output .= ' ' . $googleAdsRow->getCampaign()->getId();
}
print 'The server streaming call completed before the timeout.' . PHP_EOL;
} catch (ApiException $exception) {
if ($exception->getStatus() === ApiStatus::DEADLINE_EXCEEDED) {
print 'The server streaming call did not complete before the timeout.' . PHP_EOL;
} else {
// Bubbles up if the exception is not about timeout.
throw $exception;
}
} finally {
print 'All campaign IDs retrieved:' . ($output ?: ' None') . PHP_EOL;
}
}
การลบล้างการหมดเวลาสำหรับการเรียกแบบเอกภาค
เมธอดบริการของ Google Ads API ส่วนใหญ่ใช้การเรียกแบบเอกภาค ตัวอย่างทั่วไปคือ
GoogleAdsService.Search
และ
GoogleAdsService.Mutate
หากต้องการลบล้างระยะหมดเวลาเริ่มต้น คุณต้องเพิ่มพารามิเตอร์พิเศษเมื่อเรียกใช้เมธอด
private static function makeUnaryCall(GoogleAdsClient $googleAdsClient, int $customerId)
{
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
// Creates a query that retrieves all campaign IDs.
$query = 'SELECT campaign.id FROM campaign';
$output = '';
try {
// Issues a search request by setting a custom client timeout.
$response = $googleAdsServiceClient->search(
SearchGoogleAdsRequest::build($customerId, $query),
[
// Any unary call is retryable and has default retry settings.
// Complete information about these settings can be found here:
// https://googleapis.github.io/gax-php/master/Google/ApiCore/RetrySettings.html.
// For this particular call, the default retry settings can be found in the
// following file:
// https://github.com/googleads/google-ads-php/blob/master/src/Google/Ads/GoogleAds/V21/Services/resources/google_ads_service_client_config.json.
//
// When making an unary call, an optional argument is provided and can be
// used to override the default retry settings with given values.
'retrySettings' => [
// Sets the maximum accumulative timeout of the call, it includes all tries.
'totalTimeoutMillis' => self::CLIENT_TIMEOUT_MILLIS,
// Sets the timeout that is used for the first try to one tenth of the
// maximum accumulative timeout of the call.
// Note: This overrides the default value and can lead to
// RequestError.RPC_DEADLINE_TOO_SHORT errors when too small. We recommend
// to do it only if necessary.
'initialRpcTimeoutMillis' => self::CLIENT_TIMEOUT_MILLIS / 10,
// Sets the maximum timeout that can be used for any given try to one fifth
// of the maximum accumulative timeout of the call (two times greater than
// the timeout that is used for the first try).
'maxRpcTimeoutMillis' => self::CLIENT_TIMEOUT_MILLIS / 5
]
]
);
// Iterates over all rows in all messages and collects the campaign IDs.
foreach ($response->iterateAllElements() as $googleAdsRow) {
/** @var GoogleAdsRow $googleAdsRow */
$output .= ' ' . $googleAdsRow->getCampaign()->getId();
}
print 'The unary call completed before the timeout.' . PHP_EOL;
} catch (ApiException $exception) {
if ($exception->getStatus() === ApiStatus::DEADLINE_EXCEEDED) {
print 'The unary call did not complete before the timeout.' . PHP_EOL;
} else {
// Bubbles up if the exception is not about timeout.
throw $exception;
}
} finally {
print 'All campaign IDs retrieved:' . ($output ?: ' None') . PHP_EOL;
}
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[null,null,["อัปเดตล่าสุด 2025-08-27 UTC"],[[["\u003cp\u003eAll Google Ads API services have default timeout settings, but they can be overridden if needed.\u003c/p\u003e\n"],["\u003cp\u003eServer streaming calls, like \u003ccode\u003eGoogleAdsService.SearchStream\u003c/code\u003e, allow overriding the default timeout with \u003ccode\u003etimeoutMillis\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eUnary calls, including \u003ccode\u003eGoogleAdsService.Search\u003c/code\u003e and \u003ccode\u003eGoogleAdsService.Mutate\u003c/code\u003e, allow overriding default retry settings, such as \u003ccode\u003etotalTimeoutMillis\u003c/code\u003e, to manage timeouts.\u003c/p\u003e\n"],["\u003cp\u003eWhile custom timeouts can be set to 2 hours or more, very long-running requests may still encounter \u003ccode\u003eDEADLINE_EXCEEDED\u003c/code\u003e errors from the API.\u003c/p\u003e\n"]]],[],null,["# Timeout\n\nAll Google Ads API services have default settings including timeouts that are used\nby the [transport](/google-ads/api/docs/client-libs/php/transport). Any service of a given Google Ads API version has a\ndedicated JSON file with these default settings defined at service and method\nlevels. For example, you can find the files related to the latest Google Ads API\nversion\n[here](https://github.com/googleads/google-ads-php/tree/HEAD/src/Google/Ads/GoogleAds/V21/Services/resources).\n\nThe default settings are adequate for most use cases, but there may be times\nwhen you need to override them. The client library for PHP supports overriding\ntimeout settings for both server streaming and unary calls.\n\nYou can set the timeout to 2 hours or more, but the API may still time out\nextremely long-running requests and return a\n[`DEADLINE_EXCEEDED`](/google-ads/api/reference/rpc/v21/InternalErrorEnum.InternalError) error.\n\nOverriding timeouts for a server streaming call\n-----------------------------------------------\n\nThe only Google Ads API service method that uses this type of call is\n[`GoogleAdsService.SearchStream`](/google-ads/api/reference/rpc/v21/GoogleAdsService/SearchStream).\nTo override the default timeout, you need to add an extra parameter when calling\nthe method:\n\n\n```php\nprivate static function makeServerStreamingCall(\n GoogleAdsClient $googleAdsClient,\n int $customerId\n) {\n $googleAdsServiceClient = $googleAdsClient-\u003egetGoogleAdsServiceClient();\n // Creates a query that retrieves all campaign IDs.\n $query = 'SELECT campaign.id FROM campaign';\n\n $output = '';\n try {\n // Issues a search stream request by setting a custom client timeout.\n /** @var GoogleAdsServerStreamDecorator $stream */\n $stream = $googleAdsServiceClient-\u003esearchStream(\n SearchGoogleAdsStreamRequest::build($customerId, $query),\n [\n // Any server streaming call has a default timeout setting. For this\n // particular call, the default setting can be found in the following file:\n // https://github.com/googleads/google-ads-php/blob/master/src/Google/Ads/GoogleAds/V21/Services/resources/google_ads_service_client_config.json.\n //\n // When making a server streaming call, an optional argument is provided and can\n // be used to override the default timeout setting with a given value.\n 'timeoutMillis' =\u003e self::CLIENT_TIMEOUT_MILLIS\n ]\n );\n // Iterates over all rows in all messages and collects the campaign IDs.\n foreach ($stream-\u003eiterateAllElements() as $googleAdsRow) {\n /** @var GoogleAdsRow $googleAdsRow */\n $output .= ' ' . $googleAdsRow-\u003egetCampaign()-\u003egetId();\n }\n print 'The server streaming call completed before the timeout.' . PHP_EOL;\n } catch (ApiException $exception) {\n if ($exception-\u003egetStatus() === ApiStatus::DEADLINE_EXCEEDED) {\n print 'The server streaming call did not complete before the timeout.' . PHP_EOL;\n } else {\n // Bubbles up if the exception is not about timeout.\n throw $exception;\n }\n } finally {\n print 'All campaign IDs retrieved:' . ($output ?: ' None') . PHP_EOL;\n }\n} \nhttps://github.com/googleads/google-ads-php/blob/be0249c30c27b4760387bec6682b82c9f4167761/examples/Misc/SetCustomClientTimeouts.php#L120-L160\n\n \n```\n\n\u003cbr /\u003e\n\nOverriding timeouts for a unary call\n------------------------------------\n\nMost of the Google Ads API service methods use unary calls; typical examples are\n[`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search) and\n[`GoogleAdsService.Mutate`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Mutate).\nTo override the default timeout, you need to add an extra parameter when calling\nthe method:\n\n\n```php\nprivate static function makeUnaryCall(GoogleAdsClient $googleAdsClient, int $customerId)\n{\n $googleAdsServiceClient = $googleAdsClient-\u003egetGoogleAdsServiceClient();\n // Creates a query that retrieves all campaign IDs.\n $query = 'SELECT campaign.id FROM campaign';\n\n $output = '';\n try {\n // Issues a search request by setting a custom client timeout.\n $response = $googleAdsServiceClient-\u003esearch(\n SearchGoogleAdsRequest::build($customerId, $query),\n [\n // Any unary call is retryable and has default retry settings.\n // Complete information about these settings can be found here:\n // https://googleapis.github.io/gax-php/master/Google/ApiCore/RetrySettings.html.\n // For this particular call, the default retry settings can be found in the\n // following file:\n // https://github.com/googleads/google-ads-php/blob/master/src/Google/Ads/GoogleAds/V21/Services/resources/google_ads_service_client_config.json.\n //\n // When making an unary call, an optional argument is provided and can be\n // used to override the default retry settings with given values.\n 'retrySettings' =\u003e [\n // Sets the maximum accumulative timeout of the call, it includes all tries.\n 'totalTimeoutMillis' =\u003e self::CLIENT_TIMEOUT_MILLIS,\n // Sets the timeout that is used for the first try to one tenth of the\n // maximum accumulative timeout of the call.\n // Note: This overrides the default value and can lead to\n // RequestError.RPC_DEADLINE_TOO_SHORT errors when too small. We recommend\n // to do it only if necessary.\n 'initialRpcTimeoutMillis' =\u003e self::CLIENT_TIMEOUT_MILLIS / 10,\n // Sets the maximum timeout that can be used for any given try to one fifth\n // of the maximum accumulative timeout of the call (two times greater than\n // the timeout that is used for the first try).\n 'maxRpcTimeoutMillis' =\u003e self::CLIENT_TIMEOUT_MILLIS / 5\n ]\n ]\n );\n // Iterates over all rows in all messages and collects the campaign IDs.\n foreach ($response-\u003eiterateAllElements() as $googleAdsRow) {\n /** @var GoogleAdsRow $googleAdsRow */\n $output .= ' ' . $googleAdsRow-\u003egetCampaign()-\u003egetId();\n }\n print 'The unary call completed before the timeout.' . PHP_EOL;\n } catch (ApiException $exception) {\n if ($exception-\u003egetStatus() === ApiStatus::DEADLINE_EXCEEDED) {\n print 'The unary call did not complete before the timeout.' . PHP_EOL;\n } else {\n // Bubbles up if the exception is not about timeout.\n throw $exception;\n }\n } finally {\n print 'All campaign IDs retrieved:' . ($output ?: ' None') . PHP_EOL;\n }\n} \nhttps://github.com/googleads/google-ads-php/blob/be0249c30c27b4760387bec6682b82c9f4167761/examples/Misc/SetCustomClientTimeouts.php#L170-L223\n\n \n```\n\n\u003cbr /\u003e"]]