Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created December 14, 2011 14:43
Show Gist options
  • Save cognitom/1476853 to your computer and use it in GitHub Desktop.
Save cognitom/1476853 to your computer and use it in GitHub Desktop.
file_get_contentsで、リモートホストから取得出来ない場合の代替関数
<?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;
}
@cognitom
Copy link
Author

file_get_contents()関数でリモートホストにアクセスすることが許可されていないケース(※)で、curlで代替する方法。
※MediaTempleとかのレンタルサーバで、ときどきそういうことがあるみたい。

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