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 |
HTTPS proxy | Set the |
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
Proxy configuration priority, from highest to lowest: `RuntimeOptions` configuration, followed by `Config` configuration.
You can use the
AlibabaCloud\Tea\Utils\Utils\RuntimeOptionsclass 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\Configclass 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.