Answer the question
In order to leave comments, you need to log in
Can you explain why buffering is useful?
function display(){/* работа шаблонизатора, замена меток */}
ob_start(display);
require 'template/index.html';
ob_end_flush();
Answer the question
In order to leave comments, you need to log in
Once upon a time, php did not use a buffer and sent everything to the client at once.
Roughly like this
<?php
for ($i = 1; $i <= 100; $i++) {
echo $i;
ob_flush();
flush();
usleep(300000);
}
ob_end_flush();
<?php
$buffer = '';
for ($i = 1; $i <= 100; $i++) {
$buffer .= $i;
if (strlen($buffer) > 50) {
echo $buffer;
$buffer = '';
}
}
echo $buffer;
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$buffer = '';
function handler($ouputBuffer) {
global $buffer;
$buffer = $ouputBuffer;
}
ob_start('handler');
$ChuckNorris = 5 / 0;
ob_end_flush();
// Клиенту не полетит E_WARNING
echo "E_WARNING";
echo "<pre>";
var_dump($buffer);
echo "</pre>";
exit("File: " . __FILE__ . " Line: " . __LINE__);
You can intercept and modify the output of a script written by another developer in order to perform additional manipulations on this output or completely clear it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question