Results 1 to 8 of 8

Thread: Turning off buffering

  1. #1
    Join Date
    Nov 2002
    Mexico City

    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:
    print "Content-type:text/html\n\n";
    $|=1; # This should turn off buffering
    foreach $i (1..10) {
    	print "$t<br>";
    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.

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

  2. #2
    Join Date
    Nov 2002
    NY, USA
    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.

  3. #3
    Join Date
    Nov 2002
    Mexico City


    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?!?


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


  5. #5
    Join Date
    Nov 2002
    NY, USA
    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.

  6. #6
    Join Date
    Nov 2002
    Mexico City
    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.
    print "Content-type:text/html\n\n";
    foreach $i (1..10) {
    print "$i<br>\n";

  7. #7
    Join Date
    Mar 2003
    Burlington, Vermont
    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
    Mexico City
    Ok, thanks for your comments. :-)


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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09532 seconds
  • Memory Usage 2,918KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates