Skip to content

Instantly share code, notes, and snippets.

@tdebatty
Last active October 27, 2022 12:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tdebatty/ef01b99139dd52d2a0bcdd24120c5e00 to your computer and use it in GitHub Desktop.
Save tdebatty/ef01b99139dd52d2a0bcdd24120c5e00 to your computer and use it in GitHub Desktop.
file_get_contents with proxy support
<?php
$context = array();
$proxy = getenv("http_proxy");
if ($proxy !== null) {
$context['http'] = array(
'proxy' => str_replace("http", "tcp", $proxy),
'request_fulluri' => true
);
}
$cxContext = stream_context_create($context);
file_get_contents($file, false, $cxContext);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment