file_get_contents()でもいいんだろうけど。。。
エラーとか細かく取れそうなので。
function getJson($url) {
if (empty($url)) {
$error = "Internal error";
throw new Exception($error);
}
try{
// セッションを初期化
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 転送を実行
$json = curl_exec($ch);
// エラー番号を取得
$curlErrno = curl_errno($ch);
if($curlErrno){
$curlError = curl_error($ch);
throw new Exception($curlError);
}
// セッションを終了
curl_close($ch);
} catch (Exception $e) {
echo "Exception-".$e->getMessage();
}
return $json;
}