FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PHP does not flush output on IIS7 ..
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
PHP does not flush output on IIS7 .. [message #178594] Tue, 10 July 2012 10:53 Go to next message
brillisoft is currently offline  brillisoft
Messages: 5
Registered: July 2012
Karma: 0
Junior Member
The following PHP program was flushing output correctly on an old Win2000 server with IIS 5.x - but refuses to do the same on a Windows 2008 64 bits server running IIS7.

Rather than throwing a line on the browser every second as coded, it waits the entire loop, buffers the result, and prints all at once when the code ends running.
Re: PHP does not flush output on IIS7 .. [message #178595 is a reply to message #178594] Tue, 10 July 2012 11:06 Go to previous messageGo to next message
brillisoft is currently offline  brillisoft
Messages: 5
Registered: July 2012
Karma: 0
Junior Member
header("Content-Type: text/html; charset=utf-8");

function flush_buffers(){
ob_end_flush();
ob_flush();
flush();
ob_start();
}

ob_start();
flush_buffers();
echo "starting...<br/>\n";
for($i = 0; $i < 3; $i++) {
flush_buffers();
print "$i<br/>\n";
flush_buffers();
sleep(2);
}

flush_buffers();

print "DONE!<br/>\n";


$myFile = "test.php";
$fh = fopen($myFile, 'r');
$source = fread($fh, filesize($myFile));
$source = htmlspecialchars($source);

print "<p><hr>Here is the code of this program:<pre>\n";
echo $source;
flush()
Re: PHP does not flush output on IIS7 .. [message #178596 is a reply to message #178594] Tue, 10 July 2012 11:02 Go to previous messageGo to next message
brillisoft is currently offline  brillisoft
Messages: 5
Registered: July 2012
Karma: 0
Junior Member
On Tuesday, July 10, 2012 12:53:50 PM UTC+2, (unknown) wrote:
> The following PHP program was flushing output correctly on an old Win2000 server with IIS 5.x - but refuses to do the same on a Windows 2008 64 bits server running IIS7.
>
> Rather than throwing a line on the browser every second as coded, it waits the entire loop, buffers the result, and prints all at once when the code ends running.

header("Content-Type: text/html; charset=utf-8");

function flush_buffers(){
ob_end_flush();
ob_flush();
flush();
ob_start();
}

ob_start();
flush_buffers();
echo "starting...<br/>\n";
for($i = 0; $i < 3; $i++) {
flush_buffers();
print "$i<br/>\n";
flush_buffers();
sleep(2);
}

flush_buffers();

print "DONE!<br/>\n";


$myFile = "test.php";
$fh = fopen($myFile, 'r');
$source = fread($fh, filesize($myFile));
$source = htmlspecialchars($source);

print "<p><hr>Here is the code of this program:<pre>\n";
echo $source;
flush()
Re: PHP does not flush output on IIS7 .. [message #178597 is a reply to message #178594] Tue, 10 July 2012 11:23 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 7/10/2012 12:53 PM, brillisoft(at)gmail(dot)com wrote:
> The following PHP program was flushing output correctly on an old Win2000 server with IIS 5.x - but refuses to do the same on a Windows 2008 64 bits server running IIS7.
>
> Rather than throwing a line on the browser every second as coded, it waits the entire loop, buffers the result, and prints all at once when the code ends running.
>

You forgot to post the "following PHP program".

A few ideas:
1) It is very well possible your webserver (IIS7) decided to buffer the
results until it deemed the output worthy (big enough) to send to the
client.

2) Behaviour depends also on the way you installed PHP
(CGI/fast-cgi/isapi/more?)

3) Did you check php.ini? Maybe you are using output buffering without
knowing.

4) If you really need such behavior, you better ask in an IIS related
newsgroup.

Regards,
Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: PHP does not flush output on IIS7 .. [message #178598 is a reply to message #178597] Tue, 10 July 2012 13:42 Go to previous messageGo to next message
brillisoft is currently offline  brillisoft
Messages: 5
Registered: July 2012
Karma: 0
Junior Member
On Tuesday, July 10, 2012 1:23:20 PM UTC+2, Erwin Moller wrote:
> On 7/10/2012 12:53 PM, David wrote:
> You forgot to post the &quot;following PHP program&quot;.

I did post it .. some timing issue I guess. It is there above your post.

> A few ideas:
> 1) It is very well possible your webserver (IIS7) decided to buffer the
> results until it deemed the output worthy (big enough) to send to the
> client.

OK, I understand that and am looking for whatever implicit setting forces the buffering.

> 2) Behaviour depends also on the way you installed PHP
> (CGI/fast-cgi/isapi/more?)

It is a default installation of PHP for IIS from Microsoft, and I do see that it uses the FastCGI - the IIS FastCGI settings do contain the path of the php-cgi.exe.

> 3) Did you check php.ini? Maybe you are using output buffering without
> knowing.

I do see the php.ini file under C:\Program File...\PHP\v5.3.
Cannot edit it .. it says read only.
Is it normal to edit these files manually?
Or does the PHP5.x provide a GUI for doing such things in a more controlled way?

> 4) If you really need such behavior, you better ask in an IIS related
> newsgroup.

Good point, will look for an IIS related newsgroup.
Re: PHP does not flush output on IIS7 .. [message #178599 is a reply to message #178598] Tue, 10 July 2012 15:38 Go to previous messageGo to next message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma: 0
Member
At Tue, 10 Jul 2012 06:42:01 -0700 (PDT) brillisoft(at)gmail(dot)com wrote:

>
> On Tuesday, July 10, 2012 1:23:20 PM UTC+2, Erwin Moller wrote:
>> On 7/10/2012 12:53 PM, David wrote:
>> You forgot to post the &quot;following PHP program&quot;.
>
> I did post it .. some timing issue I guess. It is there above your post.
>
>> A few ideas:
>> 1) It is very well possible your webserver (IIS7) decided to buffer the
>> results until it deemed the output worthy (big enough) to send to the
>> client.
>
> OK, I understand that and am looking for whatever implicit setting forces the buffering.
>
>> 2) Behaviour depends also on the way you installed PHP
>> (CGI/fast-cgi/isapi/more?)
>
> It is a default installation of PHP for IIS from Microsoft, and I do see that it uses the FastCGI - the IIS FastCGI settings do contain the path of the php-cgi.exe.
>
>> 3) Did you check php.ini? Maybe you are using output buffering without
>> knowing.
>
> I do see the php.ini file under C:\Program File...\PHP\v5.3.
> Cannot edit it .. it says read only.
> Is it normal to edit these files manually?

Yep -- it is the UNIX way. It is a plain text file. I am guessing the
file is owned by an Admin account and you are not logged in as an
Admin. Or something like that.

> Or does the PHP5.x provide a GUI for doing such things in a more controlled way?

Nope. PHP5.x does not provide any sort of GUI. *Maybe* something like
phpadmin (not actually part of PHP5.x, but a separate package) might.

>
>> 4) If you really need such behavior, you better ask in an IIS related
>> newsgroup.
>
> Good point, will look for an IIS related newsgroup.
>

--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
Re: PHP does not flush output on IIS7 .. [message #178600 is a reply to message #178594] Tue, 10 July 2012 15:47 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/10/2012 6:53 AM, brillisoft(at)gmail(dot)com wrote:
> The following PHP program was flushing output correctly on an old Win2000 server with IIS 5.x - but refuses to do the same on a Windows 2008 64 bits server running IIS7.
>
> Rather than throwing a line on the browser every second as coded, it waits the entire loop, buffers the result, and prints all at once when the code ends running.
>

Not unusual. All the PHP flush() can do is flush the PHP buffers.
These are sent to the web server, which may do buffering of its own.

It could also be buffered between the web server and the client
application (i.e. server's OS, routers along the way, client OS), but
these are generally very short time and can *usually* be ignored.

When it finally gets to the client, the browser may display the data
immediately, or it may buffer it until some or all of the data comes in
(i.e. HTML tables are often buffered).

All PHP can control is the initial PHP buffers. Everything else is
beyond its control. Since the only thing you changed was your IIS, I
would suggest you look at IIS to see if there's a way to do what you want.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PHP does not flush output on IIS7 .. [message #178604 is a reply to message #178594] Wed, 11 July 2012 14:00 Go to previous messageGo to next message
brillisoft is currently offline  brillisoft
Messages: 5
Registered: July 2012
Karma: 0
Junior Member
Solution found ..

In the end it is IIS, but it is specific for Perl too.
One needs to find the web.config file inside the folder where the script sits, edit it, and at the end of the tag containing the handler for *.pl or *.cgi, add a tag for responseBufferLimit="0", to achieve something like this:

<add name="Perl CGI for .cgi" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Perl64\bin\perl.exe &quot;%s&quot; %s" resourceType="Unspecified" requireAccess="Script" preCondition="bitness64" responseBufferLimit="0"/>

<add name="Perl CGI for .pl" path="*.pl" verb="*" modules="CgiModule" scriptProcessor="C:\Perl64\bin\perl.exe &quot;%s&quot; %s" resourceType="Unspecified" requireAccess="Script" responseBufferLimit="0"/>


PHP has a different solution.
Re: PHP does not flush output on IIS7 .. [message #178618 is a reply to message #178604] Thu, 12 July 2012 09:18 Go to previous message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jul 11, 3:00 pm, brillis...@gmail.com wrote:
> Solution found ..
>
> In the end it is IIS, but it is specific for Perl too.
> One needs to find the web.config file inside the folder where the script sits, edit it, and at the end of the tag containing the handler for *.pl or *.cgi, add a tag for responseBufferLimit="0", to achieve something like this:
>
> <add name="Perl CGI for .cgi" path="*.cgi" verb="*" modules="CgiModule" scriptProcessor="C:\Perl64\bin\perl.exe &quot;%s&quot; %s" resourceType="Unspecified" requireAccess="Script" preCondition="bitness64" responseBufferLimit="0"/>
>
> <add name="Perl CGI for .pl" path="*.pl" verb="*" modules="CgiModule" scriptProcessor="C:\Perl64\bin\perl.exe &quot;%s&quot; %s" resourceType="Unspecified" requireAccess="Script" responseBufferLimit="0"/>
>
> PHP has a different solution.

This post doesn't make sense. Your problem was with PHP. You posted a
solution for Perl.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Extracting multiple matches from a string using preg_replace
Next Topic: Check out www.phpscribble.com
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 27 09:30:36 GMT 2024

Total time taken to generate the page: 0.02574 seconds