PHP integration
Send requests through an assigned static endpoint. The example reads credentials from the process environment and uses an HTTP proxy for an HTTPS target by default. It does not fetch or rotate IPs.
Before you start
Set PROXY_HOST, PROXY_PORT, PROXY_USERNAME, and PROXY_PASSWORD in the terminal, container, or deployment platform running the program. Use the current dashboard details and the port for the selected protocol. Keep actual passwords out of source control, logs, and frontend code.
Runtime and dependencies
Use PHP 8+ with the cURL extension enabled. Save as proxy_example.php.
php proxy_example.phpSet up the connection
<?php
function requiredEnv(string $name): string {
$value = getenv($name);
if ($value === false || $value === '') {
throw new RuntimeException('Missing environment variable: ' . $name);
}
return $value;
}
$host = trim(requiredEnv('PROXY_HOST'), '[]');
$host = str_contains($host, ':') ? '[' . $host . ']' : $host;
$port = filter_var(requiredEnv('PROXY_PORT'), FILTER_VALIDATE_INT,
['options' => ['min_range' => 1, 'max_range' => 65535]]);
if ($port === false) throw new RuntimeException('Invalid PROXY_PORT');
$scheme = getenv('PROXY_SCHEME') ?: 'http';
if (!in_array($scheme, ['http', 'socks5h'], true)) {
throw new RuntimeException('PROXY_SCHEME must be http or socks5h');
}
$handle = curl_init('https://ip123.in/ip.json');
curl_setopt_array($handle, [
CURLOPT_PROXY => $host,
CURLOPT_PROXYPORT => $port,
CURLOPT_PROXYTYPE => $scheme === 'socks5h' ? CURLPROXY_SOCKS5_HOSTNAME : CURLPROXY_HTTP,
CURLOPT_PROXYUSERNAME => requiredEnv('PROXY_USERNAME'),
CURLOPT_PROXYPASSWORD => requiredEnv('PROXY_PASSWORD'),
CURLOPT_NOPROXY => '',
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
]);
$body = curl_exec($handle);
$status = curl_getinfo($handle, CURLINFO_RESPONSE_CODE);
$errorCode = curl_errno($handle);
curl_close($handle);
if ($body === false || $status < 200 || $status >= 300) {
fwrite(STDERR, 'Request failed; cURL code: ' . $errorCode . '; HTTP status: ' . $status . PHP_EOL);
exit(1);
}
echo $body, PHP_EOL;PROXY_SCHEME defaults to http. For SOCKS5, set it to socks5h and use the matching SOCKS5 port so the target hostname is resolved remotely. Switching protocols does not rotate the assigned static exit.
If something goes wrong
If this example succeeds but your workload fails, check the actual request process, SDK proxy configuration, timeouts, and retry policy. Keep TLS certificate verification enabled. The sample prints lookup data or errors without credentials; redact diagnostic logs too. See the FAQ.