a simple example that will go through and get google.co.uk # q = * 5 times and output if it got it or not is pretty useless, but your question answers what you can check to see if file_get_contents succeeded before doing the next one, obviously google can be changed to something else. but that would not be very practical. plus output buffering is not output inside functions.
<?php
function _flush (){
echo(str_repeat("\n\n",256));
if (ob_get_length()){
@ob_flush();
@flush();
@ob_end_flush();
}
@ob_start();
}
function get_file($loc){
return file_get_contents($loc);
}
for($i=0;$i<=5;$i++){
$content[$i] = @get_file("http://www.google.co.uk/#q=".$i);
if($content[$i]===FALSE){
echo'Error getting google ('.$i.')<br>';
return;
}else{
echo'Got google ('.$i.')<br>';
}
ob_flush();
_flush();
}
?>
source
share