composer/composer · error · \RuntimeException
unable to find proxy host in
Error message
unable to find proxy host in {$envName} What it means
The proxy URL parsed via parse_url but produced no `host` component, so Composer cannot route traffic. Reported at src/Composer/Util/Http/ProxyItem.php:48 as 'unable to find proxy host in <envName>'.
Solutions
- Add the host: `http://proxy.example.com:8080`.
- If using a Unix-socket proxy, switch to a supported TCP host (Composer/curl need a hostname).
- Clear the env var if it was set unintentionally.
Example fix
# before HTTPS_PROXY="http://:3128" # after HTTPS_PROXY="http://squid.example.com:3128"
Defensive patterns
Strategy: validation
Validate before calling
$p = parse_url(getenv('HTTPS_PROXY') ?: '');
if (is_array($p) && !isset($p['host'])) {
throw new \InvalidArgumentException('HTTPS_PROXY has no host.');
} Try / catch
try {
$proxy = new \Composer\Util\Http\ProxyItem($val, 'HTTPS_PROXY');
} catch (\RuntimeException $e) {
if (str_starts_with($e->getMessage(), 'unable to find proxy host in')) {
// fix the URL to include a host, then retry
}
throw $e;
} Prevention
- Always include a hostname in proxy URLs.
- Validate the parsed host before Composer runs.
When it happens
Trigger: Values like `http://:8080`, `http:///path`, or a bare scheme `http://` — parse_url succeeds but $proxy['host'] is unset (line 47).
Common situations: Misformatted proxy strings missing the hostname; port-only values; proxy set to a bare scheme by mistake.
Related errors
- port 0 is reserved in
- unable to find proxy port in
- unsupported ` ` syntax
- Invalid value for COMPOSER_AUDIT_ABANDONED
- You must enable the curl extension to make https requests…
AI-assisted analysis of composer/composer@c435d285c9 (2026-08-07).
Data as JSON: /api/errors/82e9d2df9249dd19.
Report an issue: GitHub.
Appendix: source
Thrown at src/Composer/Util/Http/ProxyItem.php:48
private $optionsAuth;
/**
* @param string $proxyUrl The value from the environment
* @param string $envName The name of the environment variable
* @throws \RuntimeException If the proxy url is invalid
*/
public function __construct(string $proxyUrl, string $envName)
{
$syntaxError = sprintf('unsupported `%s` syntax', $envName);
if (strpbrk($proxyUrl, "\r\n\t") !== false) {
throw new \RuntimeException($syntaxError);
}
if (false === ($proxy = parse_url($proxyUrl))) {
throw new \RuntimeException($syntaxError);
}
if (!isset($proxy['host'])) {
throw new \RuntimeException('unable to find proxy host in ' . $envName);
}
$scheme = isset($proxy['scheme']) ? strtolower($proxy['scheme']) . '://' : 'http://';
$safe = '';
if (isset($proxy['user'])) {
$safe = '***';
$user = $proxy['user'];
$auth = rawurldecode($proxy['user']);
if (isset($proxy['pass'])) {
$safe .= ':***';
$user .= ':' . $proxy['pass'];
$auth .= ':' . rawurldecode($proxy['pass']);
}
$safe .= '@';
View on GitHub (pinned to c435d285c9)