I have the following PHP code which simply grabs a URL behind HTTP-Basic authentication and re-serves it:
<?PHP
header("Content-Type: text/xml");
$username = "username";
$password = "password";
$url = "http://s6.voscast.com:7158/admin.cgi?mode=viewxml";
$context = stream_context_create(array(
'http' => array (
'method' => "GET",
'header' => "Authorization: Basic ".base64_encode($username.":".$password)."\r\n".
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Ubuntu/11.04 Chromium/14.0.835.202 Chrome/14.0.835.202 Safari/535.1"
)
));
print file_get_contents($url, false, $context);
?>
It works without any issues locally on my Linux Mint 11 machine (v. 5.3.5), but fails on another Linux server of a client which is running 5.2.14:

It seems like it’s trying to validate the XML, which is totally unnecessary. Is there a way I can disable this feature or investigate further as to what’s going wrong?
When I look at the source of the response, I see the following:
failed to open stream: Connection refused in /home/livshin/public_html/wp-content/uploads/_radio/songinfo.php on line 16
It’s working fine locally, but is failing online? How can I further debug this?
Try a simple test case to see if you can access any internet website. e.g.
<?php echo file_get_contents('http://google.com'); ?>Assuming the code and configuration (username/password) is identical on your local machine and the server, then the problem must be that the server itself is different in some way (e.g. doesn’t have internet access).Another thing to check would be the PHP configuration on the server. Opening a URL with
file_get_contents()can be disabled using theallow_url_fopensetting.