PHP の file_get_contents は外部リソースを手軽に扱えるので、Web サービスの API を使うときに便利です。 手軽に使える反面、例外処理をちゃんと考えておかないと 4xx や 5xx のステータスコードが返ってきたときに Warnning エラーが発生します。 file_get_contents でステータスコードを取得するにはひと手間かける必要があります。 $context = stream_context_create(array( 'http' => array('ignore_errors' => true) )); $response = file_get_contents('http://example.com/', false, $context); $pos = strpos($http_response_header[0], '200'); if
![PHP の file_get_contents でステータスコードを取得する](https://cdn-ak-scissors.b.st-hatena.com/image/square/a0e915cea129091852934283824e9be8e16f2f75/height=288;version=1;width=512/https%3A%2F%2Fblog.manabusakai.com%2Fimage%2Fogp.png)