[cgiapp] Using HTTP chunked transfer with CGI::App?

Nicholas Bamber nicholas at periapt.co.uk
Fri Jun 18 12:17:02 EDT 2010


Hi Des,
I would suggest that you look into AJAX and try to handle rather more on 
the client/javascript side. If you will permit I will give some hints on 
how I would approach it. There are alternatives but I primarily use the 
YUI framework for javascript stuff.

1.) The CGI::Application part should largely just initiate the process.
2.) You need a second back-end process (not strictly part of the web 
application) to do the actual work.
3.) Your CGI::Application should support a run mode that returns a 
progress report. This would not be a web page in the normal sense. The 
MIME type should probably be "application/json" rather than "text/html" 
and you should wrap it with the JSON perl module.
4.) The YUI connection manager provides a good AJAX framework. 
http://developer.yahoo.com/yui/connection/. Using the connection manager 
the client side gets the JSON data described in 4. and parses it using 
http://developer.yahoo.com/yui/json/ .
5.) You do the actual display using 
http://developer.yahoo.com/yui/progressbar/ .

If that is all too javascript heavy for you then you should be able to 
at least do 1. and 2. Then your web page should display the status and 
put in some automatic refresh in the headers until the work is complete.

The one thing you really cannot do is leave the browser wating whilst 
the work completes.

Nicholas


> Message: 1
> Date: Fri, 18 Jun 2010 14:40:06 +0100
> From: Des Herriott <des.herriott at gmail.com>
> Subject: [cgiapp] Using HTTP chunked transfer with CGI::App?
> To: cgiapp at lists.openlib.org
> Message-ID:
> 	<AANLkTimLmmkxcuOqEoxxCd25MG7B4wiT6NN7SkmANZtd at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> I'm working on a CGI::Application app which needs to run some potentially
> slow tasks, and I want to keep the user updated about its progress.
> The runmodes I'm using:
>
> - show_request_form - display the initial request form
> - show_preview - once the user has entered their data, display
>  a list of the work that will be done
> - submit_request - carry out the actual work
>
> The submit_request runmode will run several tasks, some of which could
> be quite slow.  The overall run time of this runmode could be 20-30
> seconds, so I want to keep the user updated after each task is completed.
> It seems like HTTP chunked transfer is what I need here, but I'm having
> trouble understanding how to make it work with CGI::App.  Since CGI::App
> runmodes basically constructs the entire page and return it, I can't see
> a way to return one chunk of the page at a time.
>
> Am I missing something, is there perhaps a useful a plugin to
> progressively render some output, or is this just not going to work?
>
> Thanks,
>
>   


More information about the cgiapp mailing list