Created
June 25, 2015 08:28
-
-
Save frederikbosch/1fde7bd07a0661e397b3 to your computer and use it in GitHub Desktop.
Zlib test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'http://packagist.org/p/symfony/finder$a4bc31ef5d391952af0e7202b072f6d587ae89623277f89aefad0f9d49a9bc2c.json'; | |
$url = 'http://dump.robbast.nl/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); | |
$headersBeforeContents = stream_get_meta_data($stream); | |
$content = stream_get_contents($stream); | |
$headersAfterContents = stream_get_meta_data($stream); | |
var_dump($headersBeforeContents, $headersAfterContents, strlen($content)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment