Page 1 of 1

Using file or file_get_contents thru a proxy

Posted: Mon Dec 01, 2008 10:45 pm
by d5maul
From home I have no trouble reading a URL using file() or file_get_contents() with a URL argument. From work, internet access must be thru a proxy. I have confirmed that allow_url_fopen is enabled. The web server serving the php is running Apache 2.2 and PHP 5.x ; I am trying to use the following code to open the url and then read the file at that URL.

$r_default_context = stream_context_get_default
(
array
(
'http' => array
(
// All HTTP requests are passed through a proxy server.
'proxy' => 'http://proxy.XXX.com:81/',
// Make sure IP and port are correct!!!
'request_fulluri' => True,
),
)
);

// Though we said system wide, some extensions need a little coaxing.
libxml_set_streams_context($r_default_context);
?>

<h2>Try to parse KESetup.cfg file</h2>

$fname = "http://download.XXX.com/digital/software/XXX/file.cfg";

$lines = file($fname);

At this point my Apache error log reports:

PHP Warning: file(http://download.XXX.com/digital/software/file.cfg) [<a href='function.file'>function.file</a>]: failed to open stream: Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? in C:\\server\\htdocs\\checkforupdates\\try.php on line 41

Many google searches have come up with this error but I have not determined what to change to fix it. As I said, without the proxy (and therefore without the libxml_set_streams_context() code, this works FINE. Any ideas? Thanks in advance!!