تایم اوت
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
همه سرویسهای Google Ads API دارای تنظیمات پیشفرض از جمله مهلت زمانی هستند که توسط حمل و نقل استفاده میشود. هر سرویس از یک نسخه Google Ads API معین دارای یک فایل JSON اختصاصی است که این تنظیمات پیشفرض در سطوح سرویس و روش تعریف شده است. برای مثال، میتوانید فایلهای مربوط به آخرین نسخه Google Ads API را در اینجا پیدا کنید.
تنظیمات پیشفرض برای اکثر موارد استفاده کافی است، اما ممکن است مواردی وجود داشته باشد که لازم باشد آنها را لغو کنید. کتابخانه سرویس گیرنده برای PHP از تنظیمات بازدارنده زمان برای هر دو جریان سرور و تماس های unary پشتیبانی می کند.
میتوانید زمانبندی را روی ۲ ساعت یا بیشتر تنظیم کنید، اما 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 از تماسهای unary استفاده میکنند. نمونه های معمولی عبارتند از 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;
}
}
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-26 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-26 بهوقت ساعت هماهنگ جهانی."],[[["\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"]]