I have written a plugin and we append messages to the return_data and when the process is finished, the return_data is sent and it shows on the page.
function Event_sync() {
$this->return_data = date('h:i:s A')." - "."FIRST MESSAGE"\n";
// Do something
$this->return_data .= date('h:i:s A')." - "."SECOND MESSAGE"\n";
// Do something else
$this->return_data .= date('h:i:s A')." - "."THIRD MESSAGE"\n";
// Do something else
$this->return_data .= date('h:i:s A')." - "."LAST MESSAGE"\n";
}This produces this display:
08:57:01 AM - FIRST MESSAGE
08:59:02 AM - SECOND MESSAGE
08:62:03 AM - THIRD MESSAGE
08:64:04 AM - LAST MESSAGEBut ONLY after everything has run. However, I’d like to know if there is a way to have the messages shown as they happen vs. after the function completes?
This is how I did it in another project that didn’t use EE:
function showProgressMsg($msg)
{
echo $msg."
\n";
ob_flush();
flush();
sleep(1);
}
function Event_sync() {
ob_start ();
$this->showProgressMsg(date('h:i:s A')." - "."FIRST MESSAGE");
// Do something
$this->showProgressMsg(date('h:i:s A')." - "."SECOND MESSAGE");
// Do something else
$this->showProgressMsg(date('h:i:s A')." - "."THIRD MESSAGE");
// Do something
$this->showProgressMsg(date('h:i:s A')." - "."LAST MESSAGE");
ob_flush();
flush();
}This would produce this output in realtime:
08:57:01 AM - FIRST MESSAGE
08:59:02 AM - SECOND MESSAGE
08:62:03 AM - THIRD MESSAGE
08:64:04 AM - LAST MESSAGEIs there a way to buffer output from the plugin and show it in increments like this?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.