Output buffering on IIS7

Discussion in 'Perl Misc' started by David Hiskiyahu, Jul 8, 2012.

  1. 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?
     
    David Hiskiyahu, Jul 8, 2012
    #1
    1. Advertising

  2. David Hiskiyahu

    Guest

    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();
     
    , Jul 9, 2012
    #2
    1. Advertising

  3. David Hiskiyahu

    Guest

    And it is CGI.
     
    , Jul 9, 2012
    #3
  4. David Hiskiyahu

    Guest

    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.
     
    , Jul 9, 2012
    #4
  5. David Hiskiyahu

    Guest

    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();
    ?>
     
    , Jul 10, 2012
    #5
  6. David Hiskiyahu

    l v Guest

    On 7/9/2012 4:30 AM, wrote:
    > 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.

    --
    Len
     
    l v, Jul 11, 2012
    #6
  7. David Hiskiyahu

    Guest

    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.
     
    , Jul 11, 2012
    #7
  8. David Hiskiyahu

    Guest

    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.
     
    , Jul 12, 2012
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Mohler
    Replies:
    1
    Views:
    445
    Steve Grazzini
    Sep 16, 2003
  2. =?Utf-8?B?U2NvdHRPbmVz?=

    Buffering the output of multiple controls

    =?Utf-8?B?U2NvdHRPbmVz?=, Oct 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    515
    =?Utf-8?B?a2Fub25lcw==?=
    Oct 28, 2004
  3. Mark Riordan
    Replies:
    6
    Views:
    4,889
    Mark Riordan
    Oct 15, 2004
  4. JD

    output buffering

    JD, Nov 11, 2005, in forum: Python
    Replies:
    5
    Views:
    299
  5. Shahid Juma

    Output Buffering

    Shahid Juma, Oct 5, 2004, in forum: ASP General
    Replies:
    1
    Views:
    140
    Ray Costanzo [MVP]
    Oct 5, 2004
Loading...

Share This Page