We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin Output Buffering

Development and Programming

MrBaseball34's avatar
MrBaseball34
99 posts
11 years ago
MrBaseball34's avatar MrBaseball34

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 MESSAGE

But 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 MESSAGE

Is there a way to buffer output from the plugin and show it in increments like this?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.