PHP fread function and fread function usage
PHP tutorial fread function and Fread function usage
/*
Fread Syntax:
String Fread (Resource $handle, int $length)
Fread () reads the length of the bytes to the file pointer that is referenced by the process. Read stop as soon as possible to meet one of the following conditions:
Length of bytes already read
!eof (end of document) reached
A packet of available networks (streams)
Read 8192 bytes (open after user space flow)
*/
Fread Read File instance one
$filename = "/www.bkjia.com/local/something.txt";
$handle = fopen ($filename, "R");
$contents = Fread ($handle, FileSize ($filename));
Fclose ($handle);
Read remote server content PHP5 or later
$handle = fopen ("http://www.bkjia.com/", "RB");
$contents = Stream_get_contents ($handle);
Fclose ($handle);
//
$handle = fopen ("http://down.php100.com/", "RB");
$contents = ";
while (!feof ($handle)) {
$contents. = Fread ($handle, 8192);
}
Fclose ($handle);
/*
Sometimes the purpose of the stream is not to be marked with EOF, nor is it a fixed flag, which is why this loop is forever. This caused me a lot of trouble ...
I resolved it using the Stream_get_meta_data feature, as shown below is a break statement:
*/
$fp = Fsockopen ("mb.php100.com", 80);
if (! $fp) {
echo "$errstr ($errno)
n ";
} else {
Fwrite ($FP, "Data sent by socket");
$content = "";
while (!feof ($fp)) {
$content. = Fread ($fp, 1024);
$stream _meta_data = Stream_get_meta_data ($FP); Added line
if ($stream _meta_data[' unread_bytes '] <= 0) break; Added line
}
Fclose ($FP);
Echo $content;
}
http://www.bkjia.com/PHPjc/445443.html www.bkjia.com true http://www.bkjia.com/PHPjc/445443.html techarticle php fread function and fread function usage PHP tutorial fread function and Fread function usage/* fread syntax: string fread (Resource $handle, int $length) fread () Read the word Section length by processing ...