All Products
Search
Document Center

Alibaba Cloud SDK:Configure a timeout period

Last Updated:Oct 11, 2025

In software development, you configure timeouts to prevent a program from becoming unresponsive while waiting for a response. If you do not configure a timeout, your program can waste resources or even crash. If a timeout is too short, a task might be interrupted before it is complete, which can disrupt normal operations. Setting an appropriate timeout improves system stability and user experience. This topic describes how to configure timeouts for the V2.0 PHP SDK.

Timeout configuration methods

Note

Timeout configurations are applied in the following order of precedence: RuntimeOption configuration, Client configuration, and default configuration.

  • You can use the default configurations. The default read timeout and connection timeout are both 5 s.

  • You can configure the timeout for the current request using runtime parameters (RuntimeOptions).

    use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; // Set runtime parameters. These are valid only for requests that use this RuntimeOptions instance. $runtime = new RuntimeOptions([ "connectTimeout" => 5000, // Connection timeout setting "readTimeout" => 10000, // Read timeout setting ]); 
  • You can configure the global timeout using Config.

    use Darabonba\OpenApi\Models\Config; $config = new Config([ "connectTimeout" => 5000, // Connection timeout setting "readTimeout" => 10000, // Read timeout setting ]);