Hacker
Hacker

Reputation: 7906

Get past the proxy when using file_get_contents function

I am running on proxy and when i use function file_get_contents i get error like

Warning: file_get_contents(http://www.abc.com/) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\wamp\www\Kurogo123\lib\DataController.php on line 520

How do i solve this problem?

Upvotes: 1

Views: 1382

Answers (1)

Bud Damyanov
Bud Damyanov

Reputation: 31839

You need to create a stream context to reach beyond the proxy server. Try this:

// Define a context for HTTP.
$aContext = array(
     'http' => array(
         'proxy' => 'tcp://127.0.0.1:8080', // This needs to be the server and the port of the Proxy Server.
         'request_fulluri' => true,
         ),
     );
$cxContext = stream_context_create($aContext);

// Now all file stream functions can use this context.

$sFile = file_get_contents("http://www.example.com", false, $cxContext);

 echo $sFile;

Upvotes: 2

Related Questions