IIS7 blocks ob_flush from PHP [Answered]RSS

4 replies

Last post Sep 15, 2011 12:25 PM by Gazmataz

  • IIS7 blocks ob_flush from PHP

    Sep 09, 2011 06:18 AM|Gazmataz|LINK

     

    I'm Using Curl in a script and want to use flushing of the output buffer to give the user feedback on the progress.

    As I'm having problems with flush(); I've reduced this to the following test script

     <?php
    ob_start();

    for($i=0;$i<10;$i++){
        echo 'printing...<br />';
        ob_flush();
        flush();

        sleep(2);
    }
    ?>

     I expect my browser to show a new line saying printing... every 2 seconds (like it does on my old IIS6 server) but instead on my new box (win server 2008 r2, IIS7, fastCGI, PHP Version 5.3.6) the whole output appears at once after 10 seconds.

    I've read in a few places that this is down to IIS7 caching all output up to a default 4mB. I've also read that by adding responseBufferLimit="0" as an attribute to my PHP_viaFastCGI named handler in applicationHost.config that this is supposed to disable the buffering of IIS but this doesn't seem to work either?

    Thanks in Advance

    PHP FastCGI IIS7

  • Re: IIS7 blocks ob_flush from PHP

    Sep 09, 2011 10:37 AM|HCamper|LINK

    Hi,

    Have you checked a users Work Around

    http://forums.iis.net/p/1180834/1992752.aspx#1992752 

    from another Forum?

    I notice you have duplicate for your thread http://forums.iis.net/t/1181457.aspx

    Martin

     

     

    Windows and Linux work Together IT-Pros
    Community Member Award 2011
  • Re: IIS7 blocks ob_flush from PHP

    Sep 12, 2011 05:58 AM|Gazmataz|LINK

     Hi Martin,

    Thanks for your reply.  Yes I have redirected that last post here as I believe it was posted in the wrong section.

    Yes I have tried this and many other combinations of flushing the output buffer.  I'm sure the output buffer is being flushed from PHP as I tried the two following code snippets:

     The first - shows the end PHP output buffer length to be 90


    <?php
    ob_start();

    for($i=0;$i<10;$i++){
        echo 'printing...<br />';
        sleep(2);
    }

    $result = ob_get_length();
    echo $result;
    ob_end_flush();
    ob_flush();
    flush();
    ?>

    The Second show the PHP output buffer to be 18 on each sucessive flush indicating that the response is buffered elsewhere?

    <?php
    ob_start();

    for($i=0;$i<10;$i++){
        echo 'printing...<br />';
        $result = ob_get_length();
        echo $result;
        ob_end_flush();
        ob_flush();
        flush();
        ob_start();
        sleep(2);
    }
    ?>

    From what I've seen so far I am really trying to work out how to set the responseBufferLimit to 0 as opposed to the default 4MB on IIS7 running on a windows 2008 r2 server?

    Thanks for your help.

  • Re: IIS7 blocks ob_flush from PHP

    Sep 13, 2011 06:55 AM|HCamper|LINK

    Hi,

    I haven't done the tests your using for flush() for PHP sorry. 

    I did use the PHP manual tests and they work.

    I did some checking for additional information.

    And looking at both PHP and  the IIS 7.5 settings and configuration.

    Start with: Have you tried the suggestion. From the PHP function Manual.

     output_buffering = Off 
     ;output_handler =  
     zlib.output_compression = Off 
     ;zlib.output_handler =

      

    IIS Server and FastCGI need to be looked at for Design Security and Changes:

    You should look at FastCGI http://www.coastrd.com/cgioniis7 

    IIS Team Ruslany information http://ruslany.net/2010/03/important-update-for-iis-7-0-fastcgi-module/ that should

    provide the links for Security Updates Patches and additional settings.

    I have tried changing IIS Server with the existing Updates and the PHP Manual tests and it works.

    So it is hard to say what you need to change php.ini or FastCGI for other.

    The information should be at the links and it may take trial & error for your case.

    Martin

     

    Windows and Linux work Together IT-Pros
    Community Member Award 2011
  • Re: IIS7 blocks ob_flush from PHP

    Sep 15, 2011 12:25 PM|Gazmataz|LINK

     Hmmmm well something has budged and it's working now :)

     For all you googlers:

    I tried all the updates and all came back with "This update is not applicable to your computer" I think this is due to it being server 2008 R2 but i'm not sure.

    I had already made the php.ini changes and confirmed these with php_info(); but these didn't seem to have the required effect.

    I had already tried working with the information in the link above http://www.coastrd.com/cgioniis7 but could not get it to work without errors but after being suggested again I spent a bit more time and research on the syntax and eventually this is what I got working:

    appcmd set config "XXX.YYY.com" /section:handlers -[name='PHP_via_FastCGI'].ResponseBufferLimit:0

     - Where xxx.yyy.com was the subdomain I was trying to ob_flush() from.

    Hope that helps anyone else.

     

    Thanks for the Pointers  HCamper :)

    PHP FastCGI IIS7