cvs: phpdoc /en/reference/filesystem/functions fread.xml

From: Date: Wed, 24 Mar 2004 20:39:40 +0000
Subject: cvs: phpdoc /en/reference/filesystem/functions fread.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969359747@lists.php.net to get a copy of this message
pollita Wed Mar 24 15:39:40 2004 EDT Modified files: /phpdoc/en/reference/filesystem/functions fread.xml Log: Fix example 3. Remove erroneous note. http://cvs.php.net/diff.php/phpdoc/en/reference/filesystem/functions/fread.xml?r1=1.15&r2=1.16&ty=u Index: phpdoc/en/reference/filesystem/functions/fread.xml diff -u phpdoc/en/reference/filesystem/functions/fread.xml:1.15 phpdoc/en/reference/filesystem/functions/fread.xml:1.16 --- phpdoc/en/reference/filesystem/functions/fread.xml:1.15 Mon Dec 15 11:49:45 2003 +++ phpdoc/en/reference/filesystem/functions/fread.xml Wed Mar 24 15:39:40 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.15 $ --> +<!-- $Revision: 1.16 $ --> <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.25 --> <refentry id="function.fread"> <refnamediv> @@ -62,7 +62,7 @@ <para> When reading from network streams or pipes, such as those returned when reading <link linkend="features.remote-files">remote files</link> or from - <function>popen</function> and <function>proc_open</function>, reading + <function>popen</function> and <function>fsockopen</function>, reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the example below. </para> @@ -73,14 +73,10 @@ <![CDATA[ <?php $handle = fopen("http://www.example.com/", "rb"); -$contents = ""; -do { - $data = fread($handle, 8192); - if (strlen($data) == 0) { - break; - } - $contents .= $data; -} while (true); +$contents = ''; +while (!feof($handle)) { + $contents .= fread($handle, 8192); +} fclose($handle); ?> ]]> @@ -89,13 +85,6 @@ </para> <note> <para> - The example above has better performance than the traditional approach - using while(!<function>feof</function>), as we are saving the overhead - of a function call per iteration. - </para> - </note> - <note> - <para> If you just want to get the contents of a file into a string, use <function>file_get_contents</function> as it has much better performance than the code above.

« previous php.doc (#969359747) next »