Or about the features of managing content given in PHP.
The reason for this article was a two-day study, the results of which showed that the 
echo and 
print functions, innocuous in their performance, 
can actually work for a very long time and their performance depends on the quality of the Internet of the end user.
To begin with, if I had been told this yesterday, I would have wagged my finger at his temple with this person, but a series of tests carried out inexorably testifies to this.
')
Page generation: 1 second on a powerful server and 200 ms. on the weak.
It all started with the fact that I implemented a self-written profiler in the 
CakePHP framework and embedded a function to calculate the execution intervals after the main logical parts of the code. On the local server, everything worked fine, the profiler showed 
200-300 ms. , but on the production (the server is much more powerful, for which we have not yet caught up with the visitors), the execution time was sometimes 
1-3 seconds !
Using your favorite performance debugging method:
- $microtime = microtime(true);
 - //
 - echo (microtime(true) - $microtime);
 
, :
- print $out;
 
.
, , 
6 PHP. , , 
11-32 .Nagle algorithm, . -, Apache. .
.
, , :
- $index = !empty($_GET['index']) ? $_GET['index'] : 1;
 - $example_output = str_repeat(str_repeat("*", 1024), $index);
 -  
 - $microtime = microtime(true)*1000;
 - echo $example_output;
 - $interval = microtime(true)*1000 - $microtime;
 -  
 - echo '<br>Display Length: ', $index, ' KiB.<br>';
 -  
 - if($interval < 100 && $_GET['index'] < 100)
 -   echo '<meta http-equiv="refresh" content="1; url=?index='.($index + 1).'" />';
 -  
 - echo 'Reach end file: ', round($interval, 2), ' ms.'."<br>\n";
 
, , , 
echo 100 .
, 11 :
*****
Display Length: 11 KiB.
Reach end file: 0.07 ms.
12 :
*****
Display Length: 12 KiB.
Reach end file: 348.92 ms.
. — 
13 . ( ) — .
, 
348.92 ms , , , .
.
, PHP.
, :

:
:
1. .
2. Apache`.
3. PHP.
4. 
echo, PHP .
5. Apache .
6. PHP shutdown . , 
register_shutdown_function.
7. . .
8. PHP ( 
session_write_close).
9. Apache .
10. .
:

:
4a. 
echo. Apache.
4b. Apache , , 
echo.
8a. PHP , , .
8b. Apache .
8c. PHP .
4 , . , PHP .
.
PHP, « » , output_buffering=200K .
, . PHP:
- output_buffering — .
 - output_handler — .
 - implicit_flush — .
 
, . . 
output_buffering , PHP shutdown , .
:
php_value output_buffering 131072
, - , . :
php_flag output_buffering On
«» :

, :
.
, 
, 
echo. , , , 
11 PHP . , 
18 .
.
1984 Nagle, PHP . , , .
.
, .
. . , wget, 128 .
wget --limit-rate=1K www.test.lo/nagle_test.php?index=128
Display Length: 128 KiB.
Reach end file: 57234.61 ms.
, :
- Nagle` , , prefork TCP_NODELAY, , . , , , :
echo '*';
flush();
 - C , Apache PHP, , , , - .
 - , PHP, . , .
 - - Apach, nginx, lighttpd. . , , .
 - output_buffering = On , , , — . , .
 - «» . : — 8 ( , ). -: gzip. -, .
 - — sendbuffersize Apache, , , - .