Skip to content

Instantly share code, notes, and snippets.

@radutopala
Last active March 3, 2020 17:26
Show Gist options
  • Save radutopala/8761ac647ee165d373b0c6d727cd56ea to your computer and use it in GitHub Desktop.
Save radutopala/8761ac647ee165d373b0c6d727cd56ea to your computer and use it in GitHub Desktop.
Composer GZIP decoding test
<?php
$retries = 0;
function fetch() {
global $retries;
echo "Retry " . $retries . " | ";
$opts = array(
'http' => array(
'header' => array(
"Accept-Encoding: gzip",
"Connection: close",
"User-Agent: Composer/1.2.1 (Linux; 3.13.0-86-generic; PHP 7.0.12)"
),
'ignore_errors' => "1",
'protocol_version' => "1.1"
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://packagist.org/p/paragonie/random_compat%24f49f654e75ef0944f24b3ffb74b531f0f5a757a807bcbda5b511b85d41ff7dcb.json', false, $context);
//print_r($http_response_header);
$retries++;
if (($result = @zlib_decode($result)) !== false) {
echo "Decoded successfully!\n";
} else {
echo "Error in Decoding process! Re-fetching ...\n";
fetch();
}
}
fetch();
@radutopala
Copy link
Author

Related to discussion from composer/composer#5814

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment