Skip to content

Instantly share code, notes, and snippets.

@Ugoku
Created June 23, 2015 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ugoku/1d1e3b781821231f9daf to your computer and use it in GitHub Desktop.
Save Ugoku/1d1e3b781821231f9daf to your computer and use it in GitHub Desktop.
Composer test script
<?php
$url = 'https://packagist.org/p/symfony/finder$d376d819fde50de85ad17bb8ec9e1296899e51197cb48d7047cac6bf22a9b813.json';
$headers = array(
'User-Agent: Composer/source (Windows NT; 6.2; PHP 5.6.5)',
'Accept-Encoding: gzip',
'Connection: close',
);
$options = array(
'http' => array(
'follow_location' => 1,
'max_redirects' => 20,
'protocol_version' => 1.1,
'request_fulluri' => true,
'header' => $headers,
),
);
if ('https' === parse_url($url, PHP_URL_SCHEME)) {
$options['ssl']['SNI_enabled'] = true;
if (PHP_VERSION_ID < 50600) {
$options['ssl']['SNI_server_name'] = parse_url($url, PHP_URL_HOST);
}
}
$options['http']['header'] = uasort($options['http']['header'], function ($k) {
return preg_match('{^content-type}i', $k) ? 1 : -1;
});
$ctx = stream_context_create($options);
$result = file_get_contents($url, false, $ctx);
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment