Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    17
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Make ob_flush() work on Windows

    Unfortunately, ob_flush() doesn't work whenrunning PHP on Windows. Does somebody know any hack to make it work?

    TIA

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Works fine for me:
    PHP Code:
    <?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?

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    17
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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?

    PHP Code:
    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); 
    Quote Originally Posted by Fou-Lu View Post
    Works fine for me:
    PHP Code:
    <?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?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.

  • #5
    New Coder
    Join Date
    May 2012
    Posts
    17
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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

    Quote Originally Posted by Fou-Lu View Post
    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.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    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.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #7
    New Coder
    Join Date
    May 2012
    Posts
    17
    Thanks
    0
    Thanked 3 Times in 3 Posts
    tangoforce, thanks for reply, it clarifies. Will use ajax


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •