Install
PHP 8.1 or newer with the curl extension loaded. Guzzle comes from Composer.
php -m | grep curl
composer require guzzlehttp/guzzleRotating residential
A new cURL handle starts with no open connections, so each pass through the loop opens a new tunnel through the residential gateway and prints a new address. HTTPS targets are tunnelled with CONNECT automatically; there is nothing extra to set.
<?php
$proxy = 'http://USER:[email protected]:8000';
for ($i = 0; $i < 3; $i++) {
$ch = curl_init('https://httpbin.org/ip');
curl_setopt_array($ch, [
CURLOPT_PROXY => $proxy,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 30,
]);
$body = curl_exec($ch);
echo $body === false ? curl_error($ch) : json_decode($body)->origin, "\n";
}A static datacenter or ISP IP
Guzzle takes the proxy as a request option, set once on the client. One client reuses its cURL handles and their connections, which is what you want on a static datacenter IP. For an ISP order, use the host and port from your dashboard.
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client([
'proxy' => 'http://USER:PASS@IP:PORT',
'connect_timeout' => 10,
'timeout' => 30,
]);
foreach (['https://httpbin.org/ip', 'https://httpbin.org/headers'] as $url) {
$response = $client->get($url);
echo $response->getStatusCode(), ' ', substr((string) $response->getBody(), 0, 80), "\n";
}Keeping one identity
A Guzzle client, like a reused cURL handle, keeps its connection open between requests, so on the rotating gateway consecutive requests can share a tunnel and an address. To rotate with Guzzle, pass CURLOPT_FORBID_REUSE => true in the curl request option. For a residential address that holds across new connections, such as through a login, use a sticky session; the session setting for your account is in the dashboard. Guzzle keeps cookies only if you ask it to, with 'cookies' => true.