Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
file_get_contents で Accept-Encoding:gzip 指定
<?php
function fetchUrl( $url, $gzip = false ) {
$raw = file_get_contents( $url, false, $context = stream_context_create( array(
'http' => array(
'method' => 'GET',
'header' => 'Accept-Encoding:' . ( $gzip ? 'gzip,deflate' : 'identity' ) . "\r\n",
)
) ) );
if ( $raw === false ) {
return false;
}
return $gzip ? gzdecode( $raw ) : $raw;
}
$src1 = fetchUrl( 'http://mgng.aws.af.cm' ); // 通常
$src2 = fetchUrl( 'http://mgng.aws.af.cm', true ); // gzip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment