All Products
Search
Document Center

Alibaba Cloud SDK:Configure a timeout period

Last Updated:Jun 19, 2023

You can separately configure business parameters and runtime parameters in the Darabonba SDK. The priority levels of the timeout periods that can be configured in the Darabonba SDK are listed in descending order: the timeout periods that you configure by using RuntimeOptions, the timeout periods that you configure when you initialize the SDK client, and the default timeout periods. By default, no timeout periods are configured. If your network is unstable, we recommend that you configure a timeout period to ensure business continuity.
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\SDK\Ecs\V20140526\Ecs;
use AlibabaCloud\SDK\Ecs\V20140526\Ecs\Models\DescribeRegionsRequest;

// Configure a timeout period when you initialize the SDK client.
$config = new Config([]);
$config->connectTimeout = $connectionTimeoutMillis;
$config->readTimeout = $readTimeoutMillis;

// Configure a timeout period by using runtime parameters. The timeout period takes effect only on the requests that use the RuntimeOptions instance.
$runtimeOptions = new RuntimeOptions();
$runtimeOptions->connectTimeout = $connectionTimeoutMillis;
$runtimeOptions->readTimeout = $readTimeoutMillis;

$request = new DescribeRegionsRequest();

$client = new Ecs($config);
$client->describeRegionsWithOptions($request, $runtimeOptions)