Proxy in PHP cURL: three options

In PHP cURL a password proxy takes three options. Below is a script for HTTP and a one-line switch to SOCKS5.

HTTPHTTPSSOCKS4SOCKS5Login and passwordRotation and sticky
PHP cURL · proxy
HOST:PORT
LOGIN:••••••
CURLPROXY_HTTP
15
✓ IP: Germany, residentialRun

Why use a proxy in PHP cURL

PHP's cURL extension runs on top of libcurl. The proxy address is set with CURLOPT_PROXY, login and password with CURLOPT_PROXYUSERPWD, the type with CURLOPT_PROXYTYPE. HTTP and SOCKS4/5 are supported.

What to pick

HTTP is enough for web requests. If you need SOCKS5, use the CURLPROXY_SOCKS5_HOSTNAME type so the proxy resolves the domain. Rotation suits scraping, a sticky session a chain of requests by one user.

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 PHP cURL.

  1. Check the extension

    Run php -m and look for curl in the list. If it's missing, install the php-curl package for your PHP version.

  2. Export the proxy

    Take host, port, login and password in @SousProxyBot or the dashboard.

  3. Set the options

    CURLOPT_PROXY is host and port, CURLOPT_PROXYUSERPWD is LOGIN:PASSWORD, CURLOPT_PROXYTYPE is CURLPROXY_HTTP or CURLPROXY_SOCKS5_HOSTNAME.

  4. Run it

    Save the example as ip.php and run php ip.php.

  5. Check the IP

    The script prints JSON with the proxy address. On error, curl_error shows the text.

Code example

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

php
<?php
$ch = curl_init('https://api.ipify.org?format=json');
curl_setopt_array($ch, [
    CURLOPT_PROXY          => 'HOST:PORT',
    CURLOPT_PROXYUSERPWD   => 'LOGIN:PASSWORD',
    CURLOPT_PROXYTYPE      => CURLPROXY_HTTP, // SOCKS5: CURLPROXY_SOCKS5_HOSTNAME
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 15,
]);

$body = curl_exec($ch);
if ($body === false) {
    echo 'Error: ' . curl_error($ch) . PHP_EOL;
} else {
    echo $body . PHP_EOL;
}
curl_close($ch);

Tested by running it

We ran this example ourselves: PHP 8.3.6 · ext-curl (libcurl 8.5.0). 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
Error: CONNECT tunnel failed, response 407

Common errors

The issues people most often bring to support.

!

Call to undefined function curl_init()The cURL extension isn't loaded. Install php-curl and restart PHP-FPM or the web server.

!

407 response from the proxyCheck CURLOPT_PROXYUSERPWD: LOGIN:PASSWORD without spaces. A colon in the login breaks parsing.

!

Site sees your DNS with SOCKS5CURLPROXY_SOCKS5 resolves names locally. Replace it with CURLPROXY_SOCKS5_HOSTNAME.

!

Operation timed outWrong port or a slow IP. Compare the details in the dashboard and test the proxy on /en/tools/proxy-checker/.

Need a proxy for PHP cURL?

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

FAQ

Can I pass everything in one string?

Yes, libcurl accepts http://LOGIN:PASSWORD@HOST:PORT or socks5h://LOGIN:PASSWORD@HOST:PORT in CURLOPT_PROXY. Then CURLOPT_PROXYUSERPWD and CURLOPT_PROXYTYPE aren't needed.

Do I change anything for HTTPS sites?

No, cURL opens a CONNECT tunnel through the HTTP proxy by itself.

How do I check rotation?

Run the script several times. With rotation the IP changes; with a sticky session it stays the same.