I need my script to echo something while processing. But everything I echo after the the creation of the phpexcel object goes to buffer and only echoes after the script is finished.
Is there a workaround on this?
Here is some part of the code:
$inputFileName = 'index.xlsx';
echo "bla<br>";
// Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
echo "Hi<br>";
//Everything before here does not go to buffer.
$objPHPExcel = $objReader->load($inputFileName);
//Everything after here goes to buffer and only echoes after the script has finished running
echo "Hi<br>";
} catch (Exception $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME)
. '": ' . $e->getMessage());
}
ob_implicit_flush(true);
ob_end_flush();
echo "Hi<br>";
Already tried ob_flush()
and flush()
after the echos, but neither of them works.
Tried everything here also: How to flush output after each `echo` call?
I need it to make a COMET solution, and if i can't output the echos right away, there is no way to achieve it.
Any ideas on how to make the script talk to javascript without outputting echos during its process would be welcome!
Generally speaking, the PHExcel load()
method doesn't generate any output, so nothing will be displayed while it's executing; and there's no direct user-hooks that can be used to display anything during that process.
However, it should be possible to configure a read filter, and use that to generate output.
class readOutputFilter implements PHPExcel_Reader_IReadFilter {
$currentRow = 1;
public function readCell($column, $row, $worksheetName = '') {
if ($row != $this->currentRow) {
$this->currentRow = $row;
echo 'Row ', $row, PHP_EOL;
}
// always return true, because we want to load every cell
return true;
}
}
$outputFilter = new readOutputFilter();
$objReader->setReadFilter($outputFilter);
$objPHPExcel = $objReader->load($inputFileName);
This will display a message every new row as it starts to read, but the basic principle could be applied for other criteria instead