Created
December 14, 2011 14:43
-
-
Save cognitom/1476853 to your computer and use it in GitHub Desktop.
file_get_contentsで、リモートホストから取得出来ない場合の代替関数
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 | |
/** | |
* curl_get_contents | |
* | |
* $url = 'http://somewhere.dom/' | |
* $response = curl_get_contents($url); | |
*/ | |
function curl_get_contents($url){ | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
file_get_contents()関数でリモートホストにアクセスすることが許可されていないケース(※)で、curlで代替する方法。
※MediaTempleとかのレンタルサーバで、ときどきそういうことがあるみたい。