PHP powers many price trackers, SEO tools and WordPress plugins that fetch remote pages. Almost every PHP HTTP client sits on the cURL extension, so the proxy comes down to a few cURL options: the address, the type and the username with your token.
The examples use the cURL extension directly, then Guzzle and Laravel, which accept the proxy as a single URL. Everything works on PHP 8.1 and later.
Updated 23 November 2026
What you need
Hostgate.firstproxy.shop
HTTP / HTTPS port8000
SOCKS5 port9000
Usernameuser-country-de
PasswordYOUR_TOKEN
PHP cURL supports HTTP on port 8000 and SOCKS5 on port 9000, both with username and password. Your username and token appear on the Proxy setup page of your dashboard after your first order.
Setup
How do I connect PHP to a proxy?
Follow the steps in order. Replace YOUR_TOKEN with the token from your dashboard and change the country, city or session in the username to suit the job.
1
Check that the cURL extension is enabled
Run php -m and look for curl. On Debian and Ubuntu install it with the php-curl package, then restart PHP-FPM or your web server.
Set the gateway in CURLOPT_PROXY and the credentials in CURLOPT_PROXYUSERPWD. HTTPS targets are tunnelled automatically, so CURLOPT_HTTPPROXYTUNNEL is not needed.
Both take the proxy as one URL in the proxy request option. Guzzle also accepts an array with separate http, https and no keys when some hosts must go direct.
Run the script from step 2 on the command line with php check.php. The JSON should show the country from the username.
A working proxy returns a response like the one shown, trimmed to the main fields. The IP belongs to the exit, the city and country follow your username, and the time zone is where that IP is located, here Germany.
203.0.113.24 is a documentation address. Your result shows a real exit IP.
Targeting
How do I set country, city and session in the username?
All targeting is written into the username, so PHP needs no extra settings to change location. Parts are joined with hyphens in this order after your proxy user. The password is always your token.
Proxy username parts
Part
Format
Example
Rule
Country
-country-{cc}
-country-de
Required. Two-letter country code in lowercase. 64 countries are available.
City
-city-{city}
-city-berlin
Optional. City name in lowercase, spaces become hyphens. 172 cities are available.
Session
-session-{id}
-session-a1b2c3
Optional. Any letters and digits you choose. The same id keeps the same IP, a new id gets a new IP.
Session length
-ttl-{minutes}m
-ttl-30m
Used with a session. Residential 1 to 120 minutes, mobile 1 to 60, long-acting ISP up to 720 (12 hours).
Full usernameuser-country-de-city-berlin-session-a1b2c3-ttl-30m
The problems people run into most often with PHP, with the message you are likely to see and how to solve it.
cURL error 56: Received HTTP code 407 from proxy after CONNECT
The gateway rejected the credentials. Check CURLOPT_PROXYUSERPWD for a missing colon or extra spaces. In a Guzzle URL, wrap the token in rawurlencode() if it contains special characters.
cURL error 28: Operation timed out
Set both CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT, and keep them below the PHP max_execution_time so the script can retry instead of being killed.
cURL error 7: Failed to connect
Outbound ports 8000 or 9000 are blocked. Shared hosting often allows only ports 80 and 443 out. Ask the host to open the port or run the job from a VPS.
The IP is my server address
Another option overrode the proxy, or the request was made with file_get_contents on a different code path. Search the code base for every HTTP call and send all of them through the same client.
Parallel requests share one IP
Handles inside curl_multi that use the same session name share the IP by design. Use a different session per handle, or no session at all, when each request needs its own exit.
Products
Which FirstProxy product should you use with PHP?
All products share one account, one prepaid balance and the same gateway, so you can switch type by changing the product, not the code.
Building a scraper? The web scraping use case covers request rates, retries and product choice in more depth.
FAQ
PHP proxy questions
Short answers to what people ask most about using a proxy with PHP.
How do I use a proxy with PHP cURL?
Set CURLOPT_PROXY to gate.firstproxy.shop:8000, CURLOPT_PROXYTYPE to CURLPROXY_HTTP and CURLOPT_PROXYUSERPWD to "username:YOUR_TOKEN". HTTPS sites are tunnelled through the proxy automatically.
How do I use a SOCKS5 proxy in PHP?
Use port 9000 and set CURLOPT_PROXYTYPE to CURLPROXY_SOCKS5_HOSTNAME so the proxy resolves hostnames. Credentials go in CURLOPT_PROXYUSERPWD as with HTTP.
How do I set a proxy in Guzzle?
Pass the proxy request option with a URL such as http://username:YOUR_TOKEN@host:port, either per request or in the client defaults.
Can I use a proxy with file_get_contents?
Stream contexts have a proxy option, but credentials must be sent as a manual header and HTTPS handling is limited. The cURL extension or Guzzle is the more reliable choice.