PHP cURL Proxy Setup with Authentication and Rotation
To use RotatingProxy with PHP cURL, set the proxy host to gw.rotatingproxy.cc on port 7070 for HTTP or 7071 for SOCKS5, and pass your authentication and targeting options in the username. This guide covers the exact CURLOPT_PROXY settings, how to build the username string, and how to integrate with Guzzle for solid scraping and data collection.
- Set CURLOPT_PROXY to gw.rotatingproxy.cc:7070 and CURLOPT_PROXYUSERPWD for authentication.
- Pass network, country, and session options via underscores in the username.
- Guzzle uses a `proxy` request option with a `curl` key for advanced CURLOPT settings.
- Verify the exit IP with a simple cURL request to ipify.org or ipinfo.io.
PHP cURL Proxy Settings Location
The proxy configuration for a PHP cURL request is defined using curl_setopt() or the CURLOPT_PROXY family of constants before calling curl_exec(). You set the gateway host and port, then provide authentication credentials. For Guzzle, you pass these settings as an array within the request's `proxy` option. The core principle is the same: you tell cURL to route its TCP connection through our gateway at gw.rotatingproxy.cc.
Basic HTTP Proxy Setup on Port 7070
To route HTTP and HTTPS traffic through the gateway, use port 7070. The most straightforward method uses CURLOPT_PROXY and CURLOPT_PROXYUSERPWD. Here is a complete example for a simple request with a rotating residential IP.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://httpbin.org/ip');
curl_setopt($ch, CURLOPT_PROXY, 'gw.rotatingproxy.cc:7070');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'USERNAME_net.res:PASSWORD');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
In this example, replace USERNAME with your actual proxy user login and PASSWORD with its password. The _net.res suffix explicitly selects the rotating residential network, though it's the default. For HTTPS targets, cURL uses the HTTP CONNECT method automatically through this proxy port. This setup is ideal for scripts focused on web scraping or price monitoring.
Building the Username with Targeting and Session Options
All proxy configuration beyond the login is encoded in the username field using an underscore-separated grammar. You combine your proxy user login with key.value pairs for network, country, US state, city, and session control. The password remains just the proxy user's password. For example, to target German mobile IPs with a sticky session lasting 30 minutes, you would construct the username like this:
$login = 'USERNAME'; // Your proxy user login
$network = 'net.mob';
$country = 'cc.de';
$sessionId = 'sid.a7k2m9';
$ttl = 'ttl.30';
$username = $login . '_' . $network . '_' . $country . '_' . $sessionId . '_' . $ttl;
// $username = 'USERNAME_net.mob_cc.de_sid.a7k2m9_ttl.30'
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $username . ':PASSWORD');
You can omit options you don't need. For rank tracking in a specific US city, you might use USERNAME_net.res_cc.us_city.los-angeles. Remember, city targeting is only available for residential and mobile networks, as detailed in our city targeting guide.
Using SOCKS5 Proxy on Port 7071
If your tool or library supports SOCKS5 proxies, you can use port 7071. PHP cURL supports SOCKS5 via the CURLOPT_PROXYTYPE constant. The login process and username syntax function the same way.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.ipify.org');
curl_setopt($ch, CURLOPT_PROXY, 'gw.rotatingproxy.cc:7071');
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME); // Use CURLPROXY_SOCKS5 for SOCKS5 without hostname resolution
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'USERNAME_net.dc:PASSWORD');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
The CURLPROXY_SOCKS5_HOSTNAME type (value 7) lets the proxy perform DNS resolution, which can help avoid DNS leaks. The CURLPROXY_SOCKS5 type (value 6) sends the IP address instead. For most use cases, CURLPROXY_SOCKS5_HOSTNAME is recommended. This port is useful for certain applications that inherently prefer SOCKS5, but for general HTTP traffic, port 7070 is perfectly suitable. Learn more in our HTTP vs SOCKS5 guide.
Setting Up RotatingProxy with Guzzle
Guzzle uses cURL under the hood, so you can pass cURL options directly. For HTTP/HTTPS proxy on port 7070, set the `proxy` option to the gateway string and provide auth in the URL. You must also set the `curl` option to force cURL to use the proxy for HTTPS.
$client = new GuzzleHttp\Client();
$response = $client->request('GET', 'https://httpbin.org/headers', [
'proxy' => 'http://USERNAME_net.res:PASSWORD@gw.rotatingproxy.cc:7070',
'curl' => [
CURLOPT_PROXY => 'gw.rotatingproxy.cc:7070',
CURLOPT_PROXYUSERPWD => 'USERNAME_net.res:PASSWORD'
]
]);
echo $response->getBody();
For SOCKS5 with Guzzle, you configure it through the `curl` options array, as Guzzle's `proxy` string does not natively support the SOCKS5 scheme in all versions.
$response = $client->request('GET', 'https://ipinfo.io/json', [
'curl' => [
CURLOPT_PROXY => 'gw.rotatingproxy.cc:7071',
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME,
CURLOPT_PROXYUSERPWD => 'USERNAME_net.isp_cc.us:PASSWORD'
]
]);
Always check the current Guzzle docs for any changes in proxy handling. This pattern works well for building scalable data pipelines for ecommerce intelligence or market research.
How to Verify the Exit IP and Location
After configuring the proxy, you should verify that your traffic is exiting from the expected IP and location. Make a simple request to an IP echo service using the same proxy settings. This also confirms your authentication is working.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.ipify.org?format=json');
curl_setopt($ch, CURLOPT_PROXY, 'gw.rotatingproxy.cc:7070');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'USERNAME_cc.fr:PASSWORD');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if ($result) {
$ipData = json_decode($result, true);
echo "Your exit IP is: " . $ipData['ip'] . "\n";
}
curl_close($ch);
For more detailed location data, use https://ipinfo.io/json. If you requested a French IP (cc.fr), the response should show a French location. This is a crucial first step in testing your proxy connection. If the IP is not from the expected country, double-check your username string for typos in the country code.
Fixing Common PHP cURL Proxy Errors
Here's how to diagnose and fix them in PHP.
Error 407 (Proxy Authentication Required): This means the proxy rejected your credentials. Verify your proxy user login and password are correct, and that the proxy user is not paused or over its monthly GB cap. Ensure the entire username string (with options) and password are correctly concatenated in CURLOPT_PROXYUSERPWD. For more, see our error 407 guide.
Timeouts (CURLE_OPERATION_TIMEOUTED): Proxy connections can introduce latency. Increase cURL's timeout settings appropriately for your use case.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); // Seconds to wait for connection
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Maximum total request time
TLS/SSL Errors: When connecting to HTTPS sites via the proxy, you might encounter SSL certificate errors. You can choose to verify the peer (recommended for security) or, for testing, temporarily disable verification (not for production).
// For production, ensure you have a current CA bundle
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cacert.pem');
// For testing only
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
If the target site returns a 403 error, it may have blocked the proxy IP. This is a signal to adjust your request patterns politely or rotate IPs more frequently.
Tips for Running PHP cURL at Scale
When making many concurrent requests, manage resources and respect limits. Use curl_multi_* functions for concurrent execution, but stay within your account's concurrency limit of 1,000 connections.
$mh = curl_multi_init();
$handles = [];
for ($i = 0; $i < 50; $i++) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://scrapeme.live/shop/');
curl_setopt($ch, CURLOPT_PROXY, 'gw.rotatingproxy.cc:7070');
// Use different session IDs to rotate IPs per request
$username = 'USERNAME_net.res_sid.' . bin2hex(random_bytes(3));
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $username . ':PASSWORD');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($mh, $ch);
$handles[] = $ch;
}
// Execute the multi-handle
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running);
// Process responses and close handles
foreach ($handles as $ch) {
$content = curl_multi_getcontent($ch);
// ... process $content
curl_multi_remove_handle($mh, $ch);
curl_close($ch);
}
curl_multi_close($mh);
To control costs, implement caching to avoid re-downloading unchanged content and compress responses where possible. Monitor your traffic usage in the dashboard. For large-scale projects like AI training data collection, consider using a dedicated network like rotating datacenter proxies for lower cost and higher speed, where appropriate.
Managing Sessions and Rotation in Your Script
Control IP rotation precisely through the username. To get a new IP on every connection, omit the sid option entirely. To maintain the same IP for multiple requests (a sticky session), generate a session ID and set a time-to-live.
// Rotate every request
$usernameRotate = 'USERNAME_net.res_cc.us';
// Sticky session for 15 minutes
$sessionId = 'sid.' . substr(md5(mt_rand()), 0, 8);
$usernameSticky = 'USERNAME_net.mob_cc.jp_' . $sessionId . '_ttl.15';
Use sticky sessions when you need to maintain a login cookie or complete a multi-step process on a site like Amazon. Use rotation when you are making many independent requests, such as collecting SERP data. If your session IP changes before the TTL expires, it could be because the exit device went offline; our system will automatically move you to a new IP in the same location. Learn more in our sticky vs rotating sessions guide.
Connecting to Specific Websites and Platforms
The PHP cURL setup works universally, but some platforms may require additional headers or TLS settings. For example, when accessing Google Search, you should set a realistic User-Agent and consider adding accept-language headers. Always check the destination site's robots.txt and its service terms. Our proxies are suitable for lawful data collection from platforms like LinkedIn (for public profiles), Instagram (public content), and Zillow (for real estate data). Ensure your use case aligns with our acceptable use policy.
Questions
Can I use RotatingProxy with PHP's file_get_contents() function?
Yes, but only if you configure a stream context with HTTP proxy settings. It's generally less flexible than cURL. For reliable proxy use, especially with authentication and HTTPS, cURL or Guzzle are strongly recommended.
How do I handle proxy authentication for HTTPS requests in cURL?
cURL handles it automatically when you use CURLOPT_PROXY and CURLOPT_PROXYUSERPWD on port 7070. For HTTPS targets, cURL will issue a CONNECT command to the proxy to tunnel the TLS connection. No extra steps are needed.
My script works without proxy but fails with a 502 error when using the proxy. What does this mean?
A 502 Bad Gateway from the proxy usually indicates a temporary issue with the exit node. Implement a retry logic in your code; the next request (or retry) will likely use a different IP and succeed. Check our error 502 guide for details.
Does Guzzle 7 support SOCKS5 proxies directly via the 'proxy' option string?
The support varies. The safest method across Guzzle versions is to use the 'curl' option array to set CURLOPT_PROXYTYPE as shown in this guide. Always check the current Guzzle documentation for the version you are using.
How can I reduce the bandwidth used by my PHP scraper to lower costs?
Enable HTTP compression (set the `Accept-Encoding: gzip` header), cache responses locally, and only download necessary content (e.g., avoid images if you only need text). Our guide on saving bandwidth has more tips.
I'm getting an error that my proxy user cannot use the requested network. How do I fix this?
Each proxy user you create in the dashboard can be restricted to specific networks. Log into the dashboard, go to the proxy user settings, and ensure the network you are trying to use (e.g., mobile) is enabled for that user. See how to create a proxy user.
Start with one top-up, use any network
Create an account in a minute, add $40 or more, and the same balance pays for residential, mobile, datacenter and ISP traffic.