What is the advantage of echo fragments when outputting a file?

What is the advantage and difference between the following:

Statement 1:

header("Content-type: image/jpeg");
header('Expires: ' . date('r',time() + 864000));
header("Pragma: public");
header("Cache-Control: public");
header("Content-Length: " . strlen($contents));
$splitString = str_split($contents, 1024);
foreach($splitString as $chunk)
echo $chunk;

Statement 2:

header("Content-type: image/jpeg");
header('Expires: ' . date('r',time() + 864000));
header("Pragma: public");
header("Cache-Control: public");
header("Content-Length: " . strlen($contents));
echo $contents;
+5
source share
4 answers

Because TCP / IP packets are buffered, using them echoto send large strings to a client can cause severe performance degradation. Sometimes it can add a whole second to script processing time. This happens even when using output buffering.

, , . , 1 substr, , , 2.

+3

1 .

0

1024 , 1024 , ant, , , for .

0

$contents , , , - .

0

All Articles