Tous les produits
Search
Centre de documentation

Alibaba Cloud SDK:Configurer un délai d'expiration

Dernière mise à jour :Aug 11, 2026

Des délais d'expiration appropriés évitent l'attente indéfinie des requêtes, réduisent la consommation de ressources et améliorent la fiabilité du programme.

Méthodes de configuration

Remarque

Priorité des délais d'expiration par ordre décroissant : configuration au niveau de la requête, configuration au niveau du client, puis paramètres par défaut.

  • Utilisez les paramètres par défaut. Le délai de connexion est de 5 secondes et le délai de lecture de 10 secondes.

  • Configurez un délai d'expiration dans une requête.

    <?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;
    }
  • Définissez un délai d'expiration au niveau du client.

    <?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;
    }