Tüm Ürünler
Search
Belge Merkezi

Alibaba Cloud SDK:Zaman aşımı süresi yapılandırma

Son Güncelleme:Oct 07, 2026

Uygun zaman aşımı süreleri, isteklerin süresiz beklemesini önler, kaynak tüketimini azaltır ve programın güvenilirliğini artırır.

Yapılandırma yöntemleri

Not

Zaman aşımı önceliği azalan sırada şu şekildedir: istek düzeyi yapılandırması, istemci düzeyi yapılandırması ve varsayılan ayarlar.

  • Varsayılan ayarları kullanın. Varsayılan bağlantı zaman aşımı 5 saniye, varsayılan okuma zaman aşımı ise 10 saniyedir.

  • İstekte zaman aşımı süresi yapılandırın.

    <?php
    
    require_once 'vendor/autoload.php';
    
    use AlibabaCloud\Client\AlibabaCloud;
    use AlibabaCloud\Client\Exception\ClientException;
    use AlibabaCloud\Client\Exception\ServerException;
    use AlibabaCloud\Ecs\Ecs;
    
    try {
        // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured. 
        AlibabaCloud::accessKeyClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'))
            ->asDefaultClient();
        $request = Ecs::v20140526()->describeRegions();
        $result = $request
            ->scheme('https')
            ->version('2014-05-26')
            ->product('Ecs')
            ->action('DescribeRegions')
            ->regionId('cn-hangzhou')
            ->host("ecs.cn-hangzhou.aliyuncs.com")
            ->connectTimeout(5) // Set the timeout period for connection requests to 5 seconds. 
            ->timeout(10) // Set the timeout period for read requests to 10 seconds. 
            ->request();
        print_r($result->toArray());
    } catch (ClientException $exception) {
        // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. 
        echo $exception->getMessage() . PHP_EOL;
    } catch (ServerException $exception) {
        // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. 
        echo $exception->getMessage() . PHP_EOL;
        echo $exception->getErrorCode() . PHP_EOL;
        echo $exception->getRequestId() . PHP_EOL;
        echo $exception->getErrorMessage() . PHP_EOL;
    }
  • İstemcide zaman aşımı süresi yapılandırın.

    <?php
    
    require_once 'vendor/autoload.php';
    
    use AlibabaCloud\Client\AlibabaCloud;
    use AlibabaCloud\Client\Exception\ClientException;
    use AlibabaCloud\Client\Exception\ServerException;
    use AlibabaCloud\Ecs\Ecs;
    
    try {
        // Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured. 
        AlibabaCloud::accessKeyClient(getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'), getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'))
            ->asDefaultClient()
            ->connectTimeout(5) // Set the timeout period for connection requests to 5 seconds. 
            ->timeout(10); // Set the timeout period for read requests to 10 seconds. 
        $request = Ecs::v20140526()->describeRegions();
        $result = $request
            ->scheme('https')
            ->version('2014-05-26')
            ->product('Ecs')
            ->action('DescribeRegions')
            ->regionId('cn-hangzhou')
            ->host("ecs.cn-hangzhou.aliyuncs.com")
            ->request();
        print_r($result->toArray());
    } catch (ClientException $exception) {
        // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. 
        echo $exception->getMessage() . PHP_EOL;
    } catch (ServerException $exception) {
        // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, the information is displayed for reference only. 
        echo $exception->getMessage() . PHP_EOL;
        echo $exception->getErrorCode() . PHP_EOL;
        echo $exception->getRequestId() . PHP_EOL;
        echo $exception->getErrorMessage() . PHP_EOL;
    }