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 Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more