You shouldn’t use file_get_contents()
for remote requests. WordPress does the heavy lifting for you when determining what is compatible on your host.
Instead of file_get_contents()
use the following to check for 404s:
$request = wp_remote_get($url);
$status = $request['response']['code'];
if($status === 404){
//do something
}
You can also use wp_remote_retrieve_body($request)
to get the contents of the request.