সময় সমাপ্ত

টাইমআউট সহ সব Google Ads API পরিষেবার ডিফল্ট সেটিংস আছে যা ট্রান্সপোর্ট ব্যবহার করে। প্রদত্ত Google Ads API ভার্সনের যেকোনও পরিষেবায় একটি নির্দিষ্ট JSON ফাইল থাকে যেখানে পরিষেবা ও পদ্ধতি লেভেলে এইসব ডিফল্ট সেটিংস সংজ্ঞায়িত করা থাকে। যেমন, আপনি GitHub-এ লেটেস্ট Google Ads API ভার্সনের জন্য পরিষেবা রিসোর্স কনফিগারেশন ফাইল খুঁজে পেতে পারেন।

বেশিরভাগ ক্ষেত্রে ডিফল্ট সেটিংসই যথেষ্ট, তবে কিছু ক্ষেত্রে আপনাকে সেগুলি ওভাররাইড করতে হতে পারে। PHP-এর জন্য ক্লায়েন্ট লাইব্রেরি, সার্ভার স্ট্রিমিং এবং ইউনারি কল, উভয়ের জন্যই প্রতি-কল টাইমআউট সেটিংস (timeoutMillis বিকল্প ব্যবহার করে মিলিসেকেন্ডে নির্দিষ্ট করা) ওভাররাইড করা সমর্থন করে।

ক্লায়েন্ট লাইব্রেরিতে আপনি বেশি টাইমআউট ভ্যালু (যেমন, ২ ঘণ্টা বা তার বেশি) কনফিগার করতে পারলেও, আন্ডারলায়িং নেটওয়ার্ক প্রক্সি বা API সার্ভার এখনও বেশি সময় ধরে চলা অনুরোধ আগেভাগে বন্ধ করে দিতে পারে এবং DEADLINE_EXCEEDED স্ট্যাটাস সংক্রান্ত সমস্যা দেখাতে পারে।

সার্ভার স্ট্রিমিং কলের জন্য টাইমআউট ওভাররাইড করুন

Google Ads API পরিষেবার একমাত্র পদ্ধতি যা সার্ভার স্ট্রিমিং কল ব্যবহার করে তা হল GoogleAdsService.SearchStream। ডিফল্ট টাইম-আউট ওভাররাইড করতে, মেথড কল করার সময় ঐচ্ছিক কল বিকল্প অ্যারেতে timeoutMillis (মিলিসেকেন্ডে) পাস করুন:

    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/V26/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। ডিফল্ট টাইমআউট ওভাররাইড করতে, মেথড কল করার সময় ঐচ্ছিক কল বিকল্প অ্যারেতে timeoutMillis (মিলিসেকেন্ডে) পাস করুন:

    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/V26/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;
        }
    }