DEV Community

Cover image for file_get_contents depend on previous calls when using a proxy
Julian
Julian

Posted on • Updated on

file_get_contents depend on previous calls when using a proxy

quite interresting, that if you do two file_get_contents in a row, the 2nd one depends on the 1st one if you use a proxy server.

running the following script:

<?php
$stream_default_opts = array(
  'http'=>array(
    'proxy'=>"tcp://5.9.78.28:3128",
    'request_fulluri' => true,
  )
);


stream_context_set_default($stream_default_opts);

file_get_contents("https://www.google.com", false); 
file_get_contents("https://getcomposer.org", false); 
Enter fullscreen mode Exit fullscreen mode

leads to:

PHP Warning:  file_get_contents(https://www.google.com): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
 in foo.php on line 21
PHP Warning:  file_get_contents(): Peer certificate CN=`getcomposer.org' did not match expected CN=`www.google.com' in foo.php on line 22
PHP Warning:  file_get_contents(https://getcomposer.org): failed to open stream: Cannot connect to HTTPS server through proxy in foo.php on line 22
Enter fullscreen mode Exit fullscreen mode

ignore the 404 part, its just the public proxy i used for this demo. i get the error (the peer certificate error) when using my proxy (but not the 404 of course)

Top comments (0)