DEV Community

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

Posted on • Edited on

1 2

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)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →