PHP
Wire a dedicated static IPv4 into PHP with Guzzle, native cURL, or Laravel's Http client without DNS leaks or config:cache pitfalls.
On this page7
Because most PHP HTTP clients sit on top of libcurl, all three proxy schemes (https://, http://, and socks5h://) work consistently across the ecosystem:
| Tool | Proxy schemes | Best for |
|---|---|---|
Guzzle |
https://, http://, socks5h:// |
General PHP applications and SDKs |
Native cURL |
https://, http://, socks5h:// |
Zero-dependency PHP scripts |
Laravel Http |
https://, http://, socks5h:// |
Laravel applications (wraps Guzzle) |
Step 1. Get your proxy URL
- Open IP addresses in your Prontaro dashboard (my.prontaro.com/ips) and select your IPv4.
- Copy the
HTTPS(:443) orSOCKS5(:1080) URL under Proxy credentials.
Export the proxy string to PRONTARO_PROXY_URL:
export PRONTARO_PROXY_URL="https://user:pass@<entry>.prontaro.io:443"Guzzle (guzzlehttp/guzzle)
Install guzzlehttp/guzzle and pass PRONTARO_PROXY_URL to the proxy option:
composer require guzzlehttp/guzzle<?php
// check_guzzle.php
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
$proxyUrl = getenv('PRONTARO_PROXY_URL');
if ($proxyUrl === false || $proxyUrl === '') {
throw new RuntimeException('PRONTARO_PROXY_URL is not set');
}
$client = new Client([
'proxy' => $proxyUrl, // supports https://, http://, and socks5h://
'connect_timeout' => 5.0,
'timeout' => 15.0,
]);
$response = $client->get('https://api.ipify.org');
echo trim((string) $response->getBody()), PHP_EOL;Verify your outbound IP:
php check_guzzle.php
203.0.113.10Guzzle throws an exception on 4xx/5xx responses by default. Once api.ipify.org returns your dedicated IPv4, you can restrict destinations in the dashboard (IP addresses → Proxy credentials → Access).
Native cURL (CURLOPT_PROXY and CURLPROXY_SOCKS5_HOSTNAME)
For https:// and http:// proxies, pass the full proxy string to CURLOPT_PROXY:
<?php
// check_curl.php
$proxyUrl = getenv('PRONTARO_PROXY_URL');
if ($proxyUrl === false || $proxyUrl === '') {
throw new RuntimeException('PRONTARO_PROXY_URL is not set');
}
$ch = curl_init('https://api.ipify.org');
curl_setopt_array($ch, [
CURLOPT_PROXY => $proxyUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 15,
]);
$body = curl_exec($ch);
if ($body === false) {
throw new RuntimeException('cURL error: ' . curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("HTTP {$status}: {$body}");
}
echo trim($body), PHP_EOL;When configuring SOCKS5 explicitly via CURLOPT_PROXYTYPE, always set CURLPROXY_SOCKS5_HOSTNAME instead of CURLPROXY_SOCKS5:
<?php
// check_socks.php
// PRONTARO_SOCKS_URL="socks5h://user:pass@<entry>.prontaro.io:1080"
$parts = parse_url(getenv('PRONTARO_SOCKS_URL') ?: '');
if (!is_array($parts) || empty($parts['host']) || empty($parts['port'])) {
throw new RuntimeException('Invalid PRONTARO_SOCKS_URL');
}
$ch = curl_init('https://api.ipify.org');
curl_setopt_array($ch, [
CURLOPT_PROXY => "{$parts['host']}:{$parts['port']}",
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME, // resolves DNS on the Prontaro node
CURLOPT_PROXYUSERPWD => rawurldecode($parts['user'] ?? '') . ':' . rawurldecode($parts['pass'] ?? ''),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 15,
]);
$body = curl_exec($ch);
if ($body === false) {
throw new RuntimeException('cURL error: ' . curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("HTTP {$status}: {$body}");
}
echo trim($body), PHP_EOL;Laravel Http::withOptions
First, map the environment variable in config/services.php — calling env() directly in application code returns null after php artisan config:cache:
// config/services.php
'prontaro' => [
'proxy_url' => env('PRONTARO_PROXY_URL'),
'relay_url' => env('PRONTARO_RELAY_URL'),
],Then pass the proxy with Http::withOptions and chain ->throw() so 4xx/5xx failures raise exceptions:
use Illuminate\Support\Facades\Http;
$ip = Http::withOptions([
'proxy' => config('services.prontaro.proxy_url'),
])
->connectTimeout(5)
->timeout(15)
->get('https://api.ipify.org')
->throw()
->body();To avoid repeating withOptions across controllers, register a reusable Http::macro('prontaro', ...) inside AppServiceProvider::boot().
Common PHP issues
- Older
libcurlwithhttps://proxies.libcurl< 7.52 fails withCURLE_UNSUPPORTED_PROTOCOL. Upgradelibcurlor usehttp://user:pass@<entry>.prontaro.io:8080(target HTTPS stays end-to-end encrypted). - Long-lived workers (Octane, FrankenPHP, Horizon). Unlike in PHP-FPM, workers stay alive between requests — reuse one Guzzle
Clientto preserve keep-alive sockets and stay within concurrent connection limits. - Unchecked HTTP status in native
cURL.curl_exec()still returns the body on HTTP403or500, so always inspectCURLINFO_RESPONSE_CODE.
Calling an API through a Relay URL
To avoid proxy configuration altogether, create a Relay in the dashboard (IP addresses) and call it like any normal HTTPS base URL:
use Illuminate\Support\Facades\Http;
$response = Http::baseUrl(config('services.prontaro.relay_url'))
->withToken(config('services.partner.token'))
// Include only if you enabled a password (in the dashboard under IP addresses → Relay address → Access):
->withHeaders([
'Prontaro-Relay-Auth' => config('services.prontaro.relay_auth'),
])
->timeout(15)
->get('/v1/status')
->throw()
->json();See Relay URLs for TLS termination details and limits.
Next steps
- curl and environment variables — diagnose
407and403errors withcurl -v. - HTTP & SOCKS5 proxy — configure
access,targets, and credential rotation. - Java — examples for
HttpClient,OkHttp, and SpringRestClient.
Something wrong on this page? Contact us