...

View Full Version : Make ob_flush() work on Windows



phpdude
07-15-2012, 06:05 PM
Unfortunately, ob_flush() doesn't work whenrunning PHP on Windows. Does somebody know any hack to make it work?

TIA

Fou-Lu
07-15-2012, 06:15 PM
Works fine for me:


<?php

function shutdown()
{
ob_end_clean();
}

register_shutdown_function('shutdown');


ob_start();
print 'this is some data';

ob_flush();
print 'this is some data that will not show.';

?>


What makes you think that the output buffering is not working properly?

phpdude
07-15-2012, 07:30 PM
I need to output content parts with delay. Your code outputs them all at once on Windows.


I changed it a bit to make delays but all content is printed on screen at the end.

Any ideas about how to make it work?



ob_start();
print 'this is some data';
ob_flush();
sleep(3);
ob_start();
print 'this is some data';
ob_flush();
sleep(3);
ob_start();
print 'this is some data';
ob_flush();
sleep(3);
ob_start();
print 'this is some data';
ob_flush();
sleep(3);


Works fine for me:


<?php

function shutdown()
{
ob_end_clean();
}

register_shutdown_function('shutdown');


ob_start();
print 'this is some data';

ob_flush();
print 'this is some data that will not show.';

?>


What makes you think that the output buffering is not working properly?

Fou-Lu
07-15-2012, 08:57 PM
This behaviour used to exist when machines had low amounts of memory. You're being buffered anywhere along the chain.
Nowadays you'll need to use a client language to simulate this.

phpdude
07-15-2012, 09:42 PM
Don't think 6gb RAM is low amount... It works fine on Linux even with less RAM.
Simulating with client language is a good idea, rather complicated though


This behaviour used to exist when machines had low amounts of memory. You're being buffered anywhere along the chain.
Nowadays you'll need to use a client language to simulate this.

tangoforce
07-16-2012, 12:27 PM
This is down to your browser and how it decides to render the output. Unfortunately there is little you can do to get around that other than to implement AJAX in your page and poll a script on a regular basis to get updates / progress reports.

The ob_flush() method has been one that comes up every few months for many years with all people wanting to do the same as you - All go away disappointed because its unreliable.

Not only do you have your browser which may refuse to display part sent data, you have an ISP, their ISP, the backbone, the datacentre.... There are many places that could be buffering the output from your script. The only real way to see if this works is with a program that accepts http output and displays it as it comes in piece by piece in a TMemo or something. Thats not something your average user will have so again the ob_flush() method you're hoping to use isn't going to be reliable for you.

phpdude
07-16-2012, 02:39 PM
tangoforce, thanks for reply, it clarifies. Will use ajax :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum