Output buffering on IIS7

  • Thread starter David Hiskiyahu
  • Start date
D

David Hiskiyahu

I moved a rather simple program from an IIS 5.x that was running under ActivePerl on an old Win2000 32 bits machine to an IIS7 server running under ActivePerl 12.x on a new Windows 2008 64 bits server.

In the old place, the program would visit a number of databases in a loop, grab some data from each database, print it and go on to the next one.

$|=1 is obviously set in the beginning to let the data flush out.

While all was fine on the old server, the program just does not want to flush in the new place .. it only shows the first byte of output when it finishes running the entire code.

Looked at IIS7 settings, disabled Output Caching.
Disabled compression.

... still the same.
The output is delayed and starts to show only when the entire script finishes running.

Any clues, please?
 
B

brillisoft

Ben, thanks for your prompt reply.
5.12.x is right .. my typo.

And yes, I did exactly that when I saw that I am fighting a buffering issue- made a mini-script that does a bit of sleeping and printing in a loop, more is not needed - and posted here when I saw that the problem is exactly that and not some of my script logic.

The old server prints a row every second.
The new server waits 5 seconds then prints all:

#!/usr/bin/perl
use CGI qw/:standard/;

select((select(STDOUT), $| = 1)[0]);

print header, start_html(-title => 'test.pl page', -bgcolor => '#ffffff');

print "<P>TEST BEGIN\n";
print "<br>Going to sleep 5 seconds\n";

sleep 1; print "<br>Slept 1 second\n";
sleep 1; print "<br>Slept 1 more second, 2 seconds so far\n";
sleep 1; print "<br>Slept 1 more second, 3 seconds so far\n";
sleep 1; print "<br>Slept 1 more second, 4 seconds so far\n";
sleep 1; print "<br>Slept 1 more second, 5 seconds so far\n";

print "<p>TEST END<p><hr>\n";

print end_html();
 
B

brillisoft

The script sleeps and prints as expected when running from a black DOS window in command mode .. so it is surely not Perl that delays the print.

Must be something in the IIS7 Web Server settings.
 
B

brillisoft

Same exactly is happening with a similar PHP script, which probably means
that my thread should be kicked out of here ..:
<?php
Print "<br>Hello, World! \n";
flush();
$sleep = 2;
flush();
echo date('h:i:s') . " - going to sleep $sleep seconds now!\n";
flush();
sleep($sleep);
Print "<br>Hello again! \n";
flush();
sleep($sleep);
echo date('h:i:s') . " - going to sleep $sleep more seconds now!\n";
flush();
Print "<br>OK, slept enough.\n";
flush();

$myFile = "hello.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();
?>
 
L

l v

Ben, thanks for your prompt reply.
5.12.x is right .. my typo.

And yes, I did exactly that when I saw that I am fighting a buffering issue - made a mini-script that does a bit of sleeping and printing in a loop, more is not needed - and posted here when I saw that the problem is exactly that and not some of my script logic.

The old server prints a row every second.
The new server waits 5 seconds then prints all:

#!/usr/bin/perl
use CGI qw/:standard/;

select((select(STDOUT), $| = 1)[0]);

print header, start_html(-title => 'test.pl page', -bgcolor => '#ffffff');

print "<P>TEST BEGIN\n";
print "<br>Going to sleep 5 seconds\n";

sleep 1; print "<br>Slept 1 second\n";
sleep 1; print "<br>Slept 1 more second, 2 seconds so far\n";
sleep 1; print "<br>Slept 1 more second, 3 seconds so far\n";
sleep 1; print "<br>Slept 1 more second, 4 seconds so far\n";
sleep 1; print "<br>Slept 1 more second, 5 seconds so far\n";

print "<p>TEST END<p><hr>\n";

print end_html();

Install Fiddler2 on your PC and enable it under IE's Tool menu. This
will allow you to trace the http traffic. If I recall correctly, IIS7
recognizes the browser type and behaves differently. IIS5 does not
perform this browser check.

I do not remember if there is a solution - I was investigating a
different problem when my company was upgrading from IE6 to IE7.
 
B

brillisoft

Len, thanks for the tip .. Fiddler is great!

As for this specific issue I am investigating, Fiddler2 confirms that there is no buffering inside the browser.

The ServerGotRequest and ServerBeginResponse timestamps prove that the buffering occurs on the server side.

So .. back to square 1, IIS7 is buffering output of my scripts, be them PHP or Perl, in same way .. regardless the explicit output flushing that is coded in the scripts, and I do not see how to stop that buffering.
 
B

brillisoft

Yes Ben, that's a popular and rather justified opinion about IIS.
Yet, one has to work with some corporate restrictions and live together with other developers on same team, plus inertia of things that worked for long time before - thus IIS.

Meanwhile, I found and fixed the problem.
Things changed from IIS 5.x to IIS 7.x, and now there is a web.config file collocated with the scripts there .. popped up there by some magic.

One needs to find that 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, which I still did not find.

That's how toy Web Servers work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top