Plack-App-CGIBin-Streaming

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

NAME
    Plack::App::CGIBin::Streaming - allow old style CGI applications to use
    the plack streaming protocol

SYNOPSIS
    in your app.psgi:

     use Plack::App::CGIBin::Streaming;

     Plack::App::CGIBin::Streaming->new(root=>...)->to_app;

DESCRIPTION
    With Plack already comes Plack::App::CGIBin.
    "Plack::App::CGIBin::Streaming" serves a very similar purpose.

    So, why do I need another module? The reason is that Plack::App::CGIBin
    first collects all the output from your CGI scripts before it prints the
    first byte to the client. This renders the following simple clock script
    useless:

     use strict;
     use warnings;

     $|=0;

     my $boundary='The Final Frontier';
     print <<"EOF";
     Status: 200
     Content-Type: multipart/x-mixed-replace;boundary="$boundary";

     EOF

     $boundary="--$boundary\n";

     my $mpheader=<<'HEADER';
     Content-type: text/html; charset=UTF-8;

     HEADER

     for(1..100) {
         print ($boundary, $mpheader,
                '<html><body><h1>'.localtime()."</h1></body></html>\n");
         $|=1; $|=0;
         sleep 1;
     }

     print ($boundary);

    Although multipart HTTP messages are quite exotic, there are situations
    where you rather want to prevent this buffering. If your document is
    very large for example, each instance of your plack server allocates the
    RAM to buffer it. Also, you might perhaps send out the "<head>" section
    of your HTTP document as fast as possible to enable the browser load JS
    and CSS while the plack server is still busy with producing the actual
    document.

    "Plack::App::CGIBin::Streaming" compiles the CGI scripts using
    CGI::Compile and provides a runtime environment similar to
    "Plack::App::CGIBin". Compiled scripts are cached. For production
    environments, it is possible to precompile and cache scripts at server
    start time, see the "preload" option below.

    Every single request is represented as an object that inherits from



( run in 0.742 second using v1.01-cache-2.11-cpan-fe3c2283af0 )