Proxy in Guzzle with one option

In Guzzle a proxy is the proxy option with a string that already holds the login and password. Here is a client that prints the IP.

HTTPHTTPSSOCKS4SOCKS5Login and passwordRotation and sticky
Guzzle · proxy
http://LOGIN:PASSWORD@HOST:PORT
http://LOGIN:PASSWORD@HOST:PORT
['localhost']
15
✓ IP: Germany, residentialRun

Why use a proxy in Guzzle

Guzzle is a PHP HTTP client installed via Composer. The proxy is passed in the proxy request option: a string, or an array with http, https and no keys. With the cURL handler the http, https, socks4, socks4a, socks5 and socks5h schemes are supported.

What to pick

Take HTTP unless you have a reason not to. For SOCKS5 use the socks5h scheme so DNS goes through the proxy. Rotation for data collection, a sticky session for an API that remembers the client by IP.

Residential

from $0.6 / GB

Home ISP addresses. The main choice for accounts and protected sites.

VIP

$2 / GB

Hand-picked clean IPs, faster and more stable than regular residential.

Mobile

$4 / GB

Carrier IPs, for platforms that check addresses strictly.

Step-by-step setup

Button names are given exactly as they appear in Guzzle.

  1. Install Guzzle

    In the project folder run composer require guzzlehttp/guzzle. You need the php-curl extension; it enables SOCKS.

  2. Build the string

    Export login:pass@ip:port in @SousProxyBot and prepend http:// or socks5h://.

  3. Pass proxy

    Set 'proxy' in the Client constructor so it applies to all requests. You can also pass it to an individual $client->get().

  4. Run it

    Save the example as ip.php next to vendor and run php ip.php.

  5. Check the IP

    The script prints JSON with the proxy address.

Code example

Put in your own HOST, PORT, LOGIN and PASSWORD from the bot or the dashboard.

php
<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client([
    // SOCKS5: 'socks5h://LOGIN:PASSWORD@HOST:PORT'
    'proxy'   => 'http://LOGIN:PASSWORD@HOST:PORT',
    'timeout' => 15,
]);

$response = $client->get('https://api.ipify.org?format=json');
echo $response->getBody() . PHP_EOL;

Tested by running it

We ran this example ourselves: PHP 8.3.6 · guzzlehttp/guzzle 8.5.5. Real output below, IP hidden.

Terminal · ip.php
$ php ip.php
{"ip":"proxy IP"}

And this is the response when the password is wrong:

$ php ip.php
…
...
#15 /home/user/proxy-test/ip.php(12): GuzzleHttp\Client->get()
#16 {main}
  thrown in /home/user/proxy-test/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 1457

Common errors

The issues people most often bring to support.

!

ConnectException or 407 from the proxyCheck the login and password. Encode special characters in the password with rawurlencode.

!

The "socks5" proxy scheme is not supportedSOCKS works only with the cURL handler. Install php-curl; without it Guzzle uses the stream handler.

!

Some addresses should go directPass proxy as an array: ['http' => ..., 'https' => ..., 'no' => ['localhost', '.internal']].

!

cURL error 28: Operation timed outA slow IP or a wrong port. Test the line on /en/tools/proxy-checker/ and raise the timeout.

Need a proxy for Guzzle?

Residential, VIP and mobile IPs. HTTP and SOCKS5, pay per GB, 1 GB free to try.

FAQ

Proxy per client or per request?

Both work. The option on a specific request overrides the Client constructor value.

How do I set different proxies for http and https?

Pass an array: 'proxy' => ['http' => 'http://...', 'https' => 'http://...']. The key is the site's scheme.

How do I change the IP between requests?

Choose rotation when exporting. Nothing to change in the code.