Tag: cURL


Sending requests through a proxy

by Michael Dowling | on | in PHP | Permalink | Comments |  Share

Some network configurations require that outbound connections be sent through a proxy server. Requiring a proxy for outbound HTTP requests is a common practice in many companies, and is often something that must be configured in a client.

You can send requests with the AWS SDK for PHP through a proxy using the "request options" of a client. These "request options" are applied to each HTTP request sent from the client. One of the option settings that can be specified is the proxy option. This setting controls how the SDK utilizes a proxy.

Request options are passed to a client through the client’s factory method. Here’s an example of how you can specify a proxy for an Amazon S3 client:

use AwsS3S3Client;

$s3 = S3Client::factory(array(
    'request.options' => array(
        'proxy' => '127.0.0.1:123'
    )
));

The above example tells the client that all requests should be proxied through an HTTP proxy located at the 127.0.0.1 IP address using port 123.

Username and password

You can supply a username and password when specifying your proxy setting if needed:

$s3 = S3Client::factory(array(
    'request.options' => array(
        'proxy' => 'username:password@127.0.0.1:123'
    )
));

Proxy protocols

Because proxy support is handled through cURL, you can specify various protocols when specifying the proxy (e.g., socks5://127.0.0.1). More information on the proxy protocols supported by cURL can be found in the online cURL documentation.