www.webdeveloper.com
Results 1 to 8 of 8

Thread: Turning off buffering

  1. #1
    Join Date
    Nov 2002
    Location
    Mexico City
    Posts
    52

    Unhappy Turning off buffering (realtime script)

    Hi guys.

    I'm having a problem that is making me CRAZY. I'm trying to have a script showing evrything it does in real time. Let's say something as simple as this:
    Code:
    #!perl
    print "Content-type:text/html\n\n";
    
    $|=1; # This should turn off buffering
    
    foreach $i (1..10) {
    	$t=time();
    	print "$t<br>";
    	sleep(1);
    }
    Well... it isn't working. The page is not shown until perl finishes rendering the script. I've tried some other methods to turn off buffering, but none of them works.

    If i run the script using command line with perl, it works (the script shows one line per second).

    I don't understand why this doesn't work. I've visited a lot of Perl sites, and every example of this kind of script says that this should print one line per second to the browser. Does anyone here know what is going on? This is my system:

    Windows NT4 SP6
    Apache 1.3.27 (Win32)
    PERL 5.8 (ActiveState), also PERL 5.6 (ActiveState)

    Thank you guys. I hope someone to know the reason of this and how to fix it.

    Paco.
    Last edited by Paco Zarabozo; 03-10-2003 at 06:06 PM.

  2. #2
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    It is technically autoflushing, but it's sending its results in real time to the server, which doesn't return the script's result to the user until the program has finished executing.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Nov 2002
    Location
    Mexico City
    Posts
    52

    Question

    Yes, that's what is happening, but it's not supposed to work that way. I have seem too many scripts that can show in real time everything, including an example like mine; but i've seen them in other servers, working.

    For example: there's a site, www.cgi101.com, where they have all the online examples of the book cgi101. One of those examples is a ping script. I don't know why, but they disabled the working example, but when it was working, it showed the ping process in real time (about one ping line per second). I tried the exact script on my system, and my system doesn't show anything until the script finishes all the ping process.

    Another example, is one that you can find at http://install.xav.com/?p=genesis . This script is designed to autoinstall a perl file managing system in your own server via FTP. It asks you for a username and password for your FTP, and it starts installing the files. While it's working, you can see in realtime all the FTP process, like if you were using telnet.

    Another example, is the Visual Package Manager that comes with Perl Dev Kit from ActiveState. It starts some kind of server in a different port (not 80) and opens your browser to search for Perl Modules. When you select a perl module to install, you can see the progress in realtime, like if you were using command line (DOS).

    Ok, i've looked at several Perl documentation sites, and everyone says that for web scripts, you can acomplish this behavior by setting $|=1. Now, by looking at my router leds, i could see that the web server isn't sending a realtime response; it waits for the script to be finished to render the page. So, i went to the Apache documentation site. I found that since version 3 of Apache, if any CGI script has turned off buffering, Apache will return the script in realtime. That's all i could find in Apache's site.

    So, as you can see, there's a way to send realtime responses to the browser. Now, the question is... HOW?!?

    Paco.

  4. #4
    Join Date
    Nov 2002
    Location
    Mexico City
    Posts
    52
    Come on, guys... anyone?

    Paco.

  5. #5
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    I found that since version 3 of Apache
    I assume you mean 1.3 since there is no version 3 of Apache yet. I've found that characters will appear after 4096 are generated. Buffering is still being done by either the server (perhaps some configuration needs to be done) or buffering by the browser (in which case there isn't much you can do). But since it does work on other sites I would have to assume the server is still buffering.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  6. #6
    Join Date
    Nov 2002
    Location
    Mexico City
    Posts
    52
    Yes, i meant 1.3.x. Apache's documentation says that since version 1.3, the web server will not buffer the response of an interpreted script, so is the interpreter the one in charge of buffering.

    Anyways, is Apache (or perl, but i doubt it) the one who is buffering the response, not the browser.

    I think too that maybe i need to add some line to httpd.conf to force this behavior. I also think that is possible that this is a Windows version issue, but i have not a unix based system to verify this.

    Could be someone here be so kind to test this code on a unix based system and tell me if it works in realtime (using a browser)? Thanks a lot.
    Code:
    #!/user/bin/perl
    $|=1;
    print "Content-type:text/html\n\n";
    foreach $i (1..10) {
    print "$i<br>\n";
    sleep(1);
    }
    Paco.

  7. #7
    Join Date
    Mar 2003
    Location
    Burlington, Vermont
    Posts
    9
    I would have to believe that you're issue is one with running Apache on Windows. Even though Apache does RUN on windows, it really truely is not a windows application at heart. It tries hard, but windows I/O is just not the same as Unix/Posix I/O. If you really need to fix this problem I would go get on the Apache mailing lists or comp.infosystems.www.servers and try to get an answer there.

    If this is just tinkering, try installing Apache 2.0. It is much better designed WRT windows, and a lot less likely to bug out.

    The other answer however is that while this sort of thing is doable, its really kind of 'hokus pokus' in that HTTP user agents are not required to define what their behaviour is WRT to an ongoing page load. Modern browsers TEND to do what you want, but its quite easy to mess it up. Some form of pull technique is more in line with the way things were designed to work... HTTP really wasn't meant for this sort of work.

  8. #8
    Join Date
    Nov 2002
    Location
    Mexico City
    Posts
    52
    Ok, thanks for your comments. :-)

    Paco.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles