sylvester36 has asked for the wisdom of the Perl Monks concerning the following question:

First time poster :) I'm trying to convert and add to a Perl script that writes messages to the console. I'm finding this to be challenging due to the nature of HTTP and responses being sent as complete static pages. Is there any relatively easy way to mimic stdout thru the web? Like if I wanted the app to continuously write to a "status" page to show progress? Thanks for any help on this!
  • Comment on Status Update type output for Perl web application?

Replies are listed 'Best First'.
Re: Status Update type output for Perl web application?
by ww (Archbishop) on Jan 03, 2010 at 02:47 UTC
      Ya, I think this AJAX stuff is cool, but I'm already having a time trying to get it to work with XAMPP. When I put the .pm module on the path, i get some constructor function error at runtime.
Re: Status Update type output for Perl web application?
by WizardOfUz (Friar) on Jan 03, 2010 at 09:38 UTC

    You can use the chunked transfer encoding to write sequentially to the client. Browsers (usually) parse and display the sent data immediately after the first chunk is read.

    Update: mod_perl example

    package My::Stream; use strict; use warnings; use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Const -compile => qw( OK ); sub handler :method { my $invocant = shift; my $request_record = shift; $request_record->content_type( 'text/html' ); for ( 1 .. 10 ) { $request_record->print( "<p>$_</p>" ); $request_record->rflush; sleep 1; } return Apache2::Const::OK; } 1;
Re: Status Update type output for Perl web application?
by stonecolddevin (Parson) on Jan 03, 2010 at 19:38 UTC

    Tatsumaki is a framework written specifically for streaming content, non-blocking would help you with your continuous writing, aka streaming.

    mtfnpy

Re: Status Update type output for Perl web application?
by Khen1950fx (Canon) on Jan 04, 2010 at 08:28 UTC
    I think that something like this might be what you are looking for: CGI::ProgressBar. An example from the docs:
    #!/usr/bin/perl use strict; use warnings; use CGI::ProgressBar qw/:standard/; $|=1; my $cgi = new CGI; print header, start_html( -title =>'Example of ProgressBar', -style=>{ -src => ' ', -code => ' ', } ), h1('A Simple Example'), p('This example will update a JS/CSS text progress bar.'), progress_bar( -from=> 1, -to=> 100 ); for (1..10){ print update_progress_bar; sleep 1; } print hide_progress_bar; print p('All done.'); print end_html; exit(0);
    The documentation is sparse and confusing, but it does work well.