Using ob_flush cause results to display outside Joomla page

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
chasiv
Joomla! Intern
Joomla! Intern
Posts: 59
Joined: Sat Feb 03, 2007 3:02 am
Location: Peru, ME USA
Contact:

Using ob_flush cause results to display outside Joomla page

Post by chasiv » Thu Jan 17, 2019 2:07 pm

I have created a test page to show what is happening. I have a module that has the following code:

Code: Select all

<?php
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);

//Flush (send) the output buffer and turn off output buffering
while (@ob_end_flush());

// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);

echo "add this";

echo str_pad("",1024," ");
echo "<br />";

ob_flush();
flush();

sleep(5);

echo "Program Output";
ob_flush();
flush();
?>
This is just test code so that I can refresh the module page when long events are happening on a page so the user understands something is happening.

The code works as expected outside joomla (see https://www.cbbfl.com/flush.php). It displays the 'Add This' line. Then waits 5 seconds and displays the 'Program Output' line.

I've created a custom module to test the same. You can reach that by navigating to https://www.cbbfl.com/joomla33/home. Once there, click the 'Test' menu option.

You'll see that it runs just like flush.php did and then displays the joomla header (navigation section) and foot (copyright & To Top link). This is wrong as the output should be between these 2 sections.

Any assistance to resolve this would be greatly appreciated as I have a number of pages with longer running scripts that I would like to update the user on what is happening.

Thanks in advance for any help.
Last edited by toivo on Thu Jan 17, 2019 2:28 pm, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17422
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Using ob_flush cause results to display outside Joomla page

Post by toivo » Thu Jan 17, 2019 2:35 pm

One example that comes to mind about showing updates to the user is the Smart Search Indexer. It uses AJAX calls to display the progress bar.
Toivo Talikka, Global Moderator

chasiv
Joomla! Intern
Joomla! Intern
Posts: 59
Joined: Sat Feb 03, 2007 3:02 am
Location: Peru, ME USA
Contact:

Re: Using ob_flush cause results to display outside Joomla page

Post by chasiv » Mon Sep 30, 2019 6:12 pm

I'm back to working on this flush issue and still having the same issue. The output is displaying above the Joomla header instead of inside the article/module.

Any insight would be appreciated. I'm not looking to use an extension, I'm looking to have my custom modules work properly.

Thanks,
Chas


Locked

Return to “Joomla! 3.x Coding”