Skip to content

Instantly share code, notes, and snippets.

@sbuzonas
Created June 22, 2015 11:12
Show Gist options
  • Save sbuzonas/57cea59ed3dc5de02e54 to your computer and use it in GitHub Desktop.
Save sbuzonas/57cea59ed3dc5de02e54 to your computer and use it in GitHub Desktop.
Test script for github.com/composer/composer/issues/4121
<?php
$url = '';
$headers = array(
'User-Agent: DownloadTest',
'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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment