Skip to content
Nefo

PHP

How to Use Residential Proxies with PHP cURL

Route PHP cURL requests through Nefo residential proxies with CURLOPT_PROXY and CURLOPT_PROXYUSERPWD, then switch to SOCKS5, sticky sessions or another country by changing a few strings.

Before you start

Nefo offers residential proxies across 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials for free in the dashboard proxy generator; only routed traffic consumes your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).

PHP's cURL extension covers both HTTP and SOCKS5, and Guzzle can wrap the same settings if you prefer a higher-level client.

  • PHP 8.0+ with the curl extension enabled
  • A Nefo account with prepaid bandwidth
  • A username/password from /dashboard/generator
  • Your chosen protocol and port
  • Your target country token

PHP cURL proxy example

Set proxy options on a cURL handle:

For SOCKS5, add curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME) and use port 11000, which resolves DNS through the proxy. Change the country token to target any of 227 countries.

shell
<?php
$ch = curl_init('https://api.ipify.org');
curl_setopt($ch, CURLOPT_PROXY, 'gw.nefo.net:9000');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'USERNAME-country-us:PASSWORD');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

PHP rotating vs sticky proxy sessions

Rotating sessions give a new residential IP per request: HTTP port 9000 or SOCKS5 port 11000. Good for spreading requests across many exits.

Sticky sessions hold one IP from 1 minute up to 24 hours: HTTP port 10000 or SOCKS5 port 12000. Set CURLOPT_PROXYUSERPWD to a token like USERNAME-country-us-session-cron1-lifetime-30 to keep one IP across a job.

Geo-targeting in the PHP proxy username

Targeting is set through username tokens: country across 227 countries, US state and city, or ASN/ISP within a country. Only the username in CURLOPT_PROXYUSERPWD changes between regions.

Collect data lawfully, respect each site's terms of service, and stay within applicable law and reasonable request rates.

Frequently asked questions

Set CURLOPT_PROXYUSERPWD to 'USERNAME-country-us:PASSWORD' and keep the host and port in CURLOPT_PROXY, for example gw.nefo.net:9000. Do not put the credentials in the host string.

Start with 5 GB. Keep what you don't use.

Residential bandwidth from $0.53/GB that never expires. Card, PayPal, Apple Pay, Google Pay, Alipay and crypto.