Check if file_get_contents is complete

In any case, I can check if file_get_contents has finished downloading the file, so I can upload another file, will it automatically upload one file before moving on to the next?

+3
source share
3 answers

Uploading a file using will file_get_contents()block your script from working until PHP has finished reading it completely. He must, because you could not appoint $content =otherwise.

+18
source

PHP - . php_threading PECL, , , , .

+1

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();
}
?>
0
source

All Articles