Integrations · Intermediate

Proxies in Go and PHP: net/http Transport, x/net/proxy, cURL and Guzzle

Configure an HTTP or SOCKS proxy explicitly in Go and PHP, keep credentials out of logs, and set timeouts. The examples cover http.Transport, cURL and Guzzle; gateway settings control which exit the client receives.

2 min read 6 sections Reviewed Editorial team Proxy Cyber

Go: http.Transport#

Go
package main

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
	"time"
)

func main() {
	proxyURL, _ := url.Parse("http://USER-cc-us:PASS@res.proxy-cyber.com:9000")
	client := &http.Client{
		Timeout: 45 * time.Second,
		Transport: &http.Transport{
			Proxy:             http.ProxyURL(proxyURL),
			DisableKeepAlives: true, // new connection = new exit on the rotating gateway
		},
	}
	resp, err := client.Get("https://api.ipify.org")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}

Connection reuse and IP assignment are different controls. A client session reuses sockets; only the assigned gateway determines rotation and sticky-session behavior. Use the session parameters supplied with your service, and verify the exit over several requests. Closing a socket or sending Connection: close does not guarantee a different IP.

Go: choosing the proxy per request#

Go
tr := &http.Transport{
	Proxy: func(r *http.Request) (*url.URL, error) {
		sid := r.Header.Get("X-Session") // your own hint, never sent to the proxy
		r.Header.Del("X-Session")
		return url.Parse(fmt.Sprintf("http://USER-cc-de-sid-%s-ttl-10m:PASS@res.proxy-cyber.com:9000", sid))
	},
}

Go: SOCKS5#

Go
import "golang.org/x/net/proxy"

dialer, err := proxy.SOCKS5("tcp", "res.proxy-cyber.com:9001", &proxy.Auth{User: "USER-cc-us", Password: "PASS"}, proxy.Direct)
if err != nil { panic(err) }
tr := &http.Transport{Dial: dialer.Dial}
client := &http.Client{Transport: tr, Timeout: 45 * time.Second}

PHP: cURL#

PHP
<?php
$ch = curl_init("https://api.ipify.org");
curl_setopt_array($ch, [
    CURLOPT_PROXY          => "http://res.proxy-cyber.com:9000",
    CURLOPT_PROXYUSERPWD   => "USER-cc-us:PASS",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 15,
    CURLOPT_TIMEOUT        => 45,
    CURLOPT_FORBID_REUSE   => true, // new exit per call on the rotating gateway
]);
echo curl_exec($ch);

// SOCKS5 with remote DNS
curl_setopt($ch, CURLOPT_PROXY, "res.proxy-cyber.com:9001");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);

PHP: Guzzle#

PHP
<?php
use GuzzleHttp\Client;

$sticky = "http://USER-cc-de-city-berlin-sid-cart42-ttl-15m:PASS@res.proxy-cyber.com:9000";
$client = new Client(['proxy' => $sticky, 'timeout' => 45, 'connect_timeout' => 15]);

$r = $client->get('https://api.ipify.org');
echo $r->getBody();

Checklist#

  • Use a distinct session identifier for each independent workflow, where the assigned gateway supports it. Confirm the permitted duration and location parameters in your connection details. A residential device can disconnect before the requested duration; a sticky session is not a guarantee of the same IP for days. For a fixed address, compare a dedicated static product.
  • Timeouts scaled to the exit type; one retry on transport errors.
  • Never log the proxy URL: it contains the password. Log the session id instead.

Questions people ask#

Does Go's http.ProxyFromEnvironment work?

Yes: export HTTPS_PROXY and HTTP_PROXY with the Proxy Cyber URL and use http.ProxyFromEnvironment as the Transport's Proxy function. NO_PROXY excludes local hosts.

Your account

Manage your proxies in one account

Compare networks, place orders and follow your balance and support requests from one dashboard. Our team reviews payments and provides connection details after delivery.

Create account