-
-
Save lixingcong/a49993d0ba05103d6b7956026632733b to your computer and use it in GitHub Desktop.
file_get_contents で Accept-Encoding:gzip 指定
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 | |
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