All Products
Search
Document Center

Alibaba Cloud SDK:Proxy configuration

Last Updated:Oct 11, 2025

In software development, a proxy is an intermediary that controls access to a feature or resource. You can use a proxy to implement features such as permission checks, operation logs, cached data, and lazy loading without changing your original code. This makes your program more secure, improves its performance, and makes it easier to maintain and extend. This topic describes how to configure a proxy for the V2.0 PHP SDK.

Proxy types

The SDK supports HTTP and HTTPS proxies.

Proxy type

Description

HTTP proxy

Set the httpProxy parameter to the IP address and port of the proxy server. The format is http://<IP address>:<port>. This setting applies only to requests that use the HTTP protocol.

HTTPS proxy

Set the httpsProxy parameter to the IP address and port of the proxy server. The format is http://<IP address>:<port>. This setting applies only to requests that use the HTTPS protocol.

Note

If the proxy server requires identity authentication, add the username and password before the IP address. The format is http://<user>:<password>@<IP address>:<port> or socks5://<user>:<password>@<IP address>:<port>.

Additionally, after you configure a proxy, you can use the noProxy parameter to specify a list of addresses to bypass the proxy. Separate multiple addresses with a comma. Domain names and IP addresses are supported.

Proxy configuration methods

Note

Proxy configuration priority, from highest to lowest: `RuntimeOptions` configuration, followed by `Config` configuration.

  • You can use the AlibabaCloud\Tea\Utils\Utils\RuntimeOptions class to configure a proxy for the current request.

    use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
    
    // Runtime parameter settings. These settings apply only to requests that use these runtime parameters.
    $runtime = new RuntimeOptions([
        "httpProxy" => "http://127.0.0.1:8080",
        "httpsProxy" => "https://username:password@proxyServer:port",
        "noProxy" => "127.0.0.1,localhost"
    ]);
     
  • You can use the Darabonba\OpenApi\Models\Config class to configure a proxy for all requests.

    use Darabonba\OpenApi\Models\Config;
    
    $config = new Config([
        "protocol" => 'https', // The request protocol determines which proxy parameter to use. `httpsProxy` applies only to HTTPS requests, and `httpProxy` applies only to HTTP requests.
        // Proxy settings
        "httpProxy" => "http://127.0.0.1:8080",
        "httpsProxy" => "https://username:password@proxyServer:port",
        "noProxy" => "127.0.0.1,localhost"
    ]);
     

References

For more information, see HTTP proxy configuration practice.