Third-party get_contents file behind the proxy server

I use a third-party library that uses file_get_contents () to retrieve external documents. Since I am behind the proxy server, I got an error:

file_get_contents(http://json-ld.org/contexts/person.jsonld): failed to open stream: Connection timed out

I tested get_contents () file with proxy setting via stream_context_create ():

$context = stream_context_create([
  'http' => [
    'proxy' => 'tcp://SERVERNAME:PORT',
    'request_fulluri' => true
  ]
]);

and it works great !!

The problem is that I cannot configure a third-party library with proxy settings. Is there a way to configure this proxy setting so that file_get_contents () can use this parameter, for example with curl?

export http_proxy=http://SERVERNAME:PORT

it works fine with curl from third-party libraries. But file_get_contents () does not seem to recognize environment variables.

export http_proxy=tcp://SERVERNAME:PORT
export tcp_proxy=tcp://SERVERNAME:PORT

both do not work.

+4

Source: https://habr.com/ru/post/1615700/


All Articles