Curl extension don't uses http proxy specified by environment variable
In curl extension, http proxy can be specified not only via CURLOPT_PROXY option, but also by environment variable called http_proxy. It seems like hhvm ignore this moment.
It can be easy reproduced. With this nginx config:
http {
server {
listen 127.0.0.1:200;
location / {
return 200 'Response from 200 port';
}
}
server {
listen 127.0.0.1:300;
location / {
return 200 'Response from 300 port';
}
}
}
And this script:
function check($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
fwrite(STDOUT, sprintf("Response: '%s', ", $response));
fwrite(STDOUT, sprintf("Proxy env: '%s'\n", getenv('http_proxy')));
}
putenv('http_proxy=');
check('http://127.0.0.1:200');
putenv('http_proxy=http://127.0.0.1:300/');
check('http://127.0.0.1:200');
I get following results using native php:
root@44d039b2efcf:~# php -v
PHP 5.5.9-1ubuntu4.6 (cli) (built: Feb 13 2015 19:17:11)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
root@44d039b2efcf:~# php check.php
Response: 'Response from 200 port', Proxy env: ''
Response: 'Response from 300 port', Proxy env: 'http://127.0.0.1:300/'
And these from hhvm:
root@44d039b2efcf:~# hhvm --version
HipHop VM 3.5.1 (rel)
Compiler: tags/HHVM-3.5.1-0-gb723e67c88bc008676687a04dff00db1faf250b3
Repo schema: a395edf8708632a3d09f417dbd9b1bd1d5b50bbe
root@44d039b2efcf:~# hhvm check.php
Response: 'Response from 200 port', Proxy env: ''
Response: 'Response from 200 port', Proxy env: 'http://127.0.0.1:300/'
Second request was sended to 200 port, instead of 300. Is this bug or I miss something?
So the problem here is that putenv doesn't actually set the environment for the process (requests run in threads so that would be unsafe), but then curl doesn't see the http_proxy environment variable.
The general problem of forwarding the environment is hard but maybe we can come up with a more targeted solution for this.
@paulbiss Should this be considered a duplicate of https://github.com/facebook/hhvm/issues/7378?
I am going over old issues on this repository, to see which ones apply to the current versions of hhvm.
As Jesse found, this is the same putenv issue.