I've implemented a file optimization script which takes about 30 seconds or more. There's a loop in which I added echos to track what's being processed.
However, most of the time, no output is being sent, until the end of the process.
How can I control this in order to send the echos in an iteration just as they're being finished?
EDIT:
This is the implied code, with the output buffer functions:
set_time_limit(60);
ini_set("memory_limit", "256M");
$documents = $this->documents_model->get($date1, $date2);
ob_start();
echo '-- Start ' . "<br>\n";
ob_end_flush();
flush();
foreach ($documents as $document) {
ob_start();
echo '-- Processing document ' . $document->id . "<br>\n";
$file = $document->get_file_name();
if (! $file || ! file_exists(DOCUMENT_ROOT . 'documents/' . $file)) {
echo '---- Document ' . $document->id . " has no PDF file yet or it was deleted<br>\n";
$path = $this->documents_model->generatePDF($document);
echo '------ file generated: ' . $path;
}
ob_end_flush();
flush();
}
echo '-- End ' . "<br>\n";