Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP flush stopped flushing in IIS7.5

Tags:

php

iis-7.5

We have been using php flush to "blank" a page immediately as soon as it is clicked, and also to send the navigation and main components of the page so that a page appears nearly instantly, even though sometimes the content may take a long time to load.

This has been working very well.

Recently we upgraded from IIS 7.0 to 7.5 and now flush does not work. While investigating the problem we have turned off compression for both static and dynamic files. We have also turned off output caching.

We also have zlib compression turned off and output buffering off in php.ini.

In order to test the problem we have the following script

@ini_set("output_buffering", "Off");
@ini_set('implicit_flush', 1);
@ini_set('zlib.output_compression', 0);

ob_start();

echo "starting...<br/>\n";
for($i = 0; $i < 5; $i++) {
    print "$i<br/>\n";
    ob_end_flush(); 
    ob_flush();
    flush();
    ob_start();
    sleep(2);
}
print "DONE!<br/>\n";

The browser just shows the loading status (whatever that is in any browser, in IE it looks like an Ajax animated gif, in Firefox the tab will say "Connecting...") for 10 seconds, and then suddenly the entire output appears.

We have tried various combinations of flush and ob_flush and ob_end_flush based upon similar questions on this site. None of them work. Is there any way to make IIS/PHP flush the data?

like image 266
Jeff Davis Avatar asked Aug 24 '11 15:08

Jeff Davis


2 Answers

There is another way to set the Response Limit using the IIS Manager:

  1. On the server main page, under "Management", select "Configuration Editor";
  2. under "Section", enter 'system.webServer/handlers';
  3. next to "(Collection)" click "..." OR mark the element "(Collection)" and, under "Actions" und '(Collection)' Element, click "Edit Items";
  4. scroll down until you find your PHP version under "Name";
  5. at the bottom, the Properties are shown an can be edited manually, including responseBufferLimit, which should be set to 0 for flush() to work.

The big Pro is that you can edit the properties for everything, not only PHP plus you can work with different versions (or even installations of the same version) of PHP.

HTH

like image 191
Dario Avatar answered Oct 30 '22 05:10

Dario


You must set the ResponseBufferLimit value of the desired handler to a number low enough to actually flush. I recommend using 0 since it prevents IIS from doing anything but passing along what you send it from your PHP script. You can use the following command line to set the ResponseBufferLimit to 0 for the php handler (just change “NAME” to the name of the handler you want to update e.g. PHP53_via_FastCGI):

appcmd.exe set config /section:handlers "/[name='NAME'].ResponseBufferLimit:0"

Alternatively, you can edit the applicationHost.config directly and add a ResponseBufferLimit attribute the XML element.

like image 35
Justin Avatar answered Oct 30 '22 06:10

Justin