Skip to content

Instantly share code, notes, and snippets.

@frederikbosch
Created June 24, 2015 08:24
Show Gist options
  • Save frederikbosch/27b0620e153d3d9b3116 to your computer and use it in GitHub Desktop.
Save frederikbosch/27b0620e153d3d9b3116 to your computer and use it in GitHub Desktop.
<?php
$url = 'http://packagist.org/p/symfony/finder$a4bc31ef5d391952af0e7202b072f6d587ae89623277f89aefad0f9d49a9bc2c.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;
});
var_dump($options['http']['header']);exit;
*/
$options['http']['header'] = implode ("\n", $options['http']['header']);
$ctx = stream_context_create($options);
$stream = fopen($url, 'r', false, $ctx);
$headers = stream_get_meta_data($stream);
$content = stream_get_contents($stream);
var_dump($headers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment