note 50401 deleted from function.echo by googleguy
| From: | googleguy@php.net | Date: | Wed, 22 Jan 2014 20:54:40 +0000 |
| Subject: | note 50401 deleted from function.echo by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198311@lists.php.net to get a copy of this message | ||
Note Submitter: ryan at wonko dot com
----
Due to the way TCP/IP packets are buffered, using echo to send large strings to the client may cause
a severe performance hit. Sometimes it can add as much as an entire second to the processing time of
the script. This even happens when output buffering is used.
If you need to echo a large string, break it into smaller chunks first and then echo each chunk. The
following function will do the trick in PHP5:
<?php
function echobig($string, $bufferSize = 8192)
{
$splitString = str_split($string, $bufferSize);
foreach($splitString as $chunk)
echo $chunk;
}
?>