[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Help using FastCGI


hi Prakash,

I haven't used FastCGI or the CGI::Application::FastCGI module, however
I have used , and do use , PersistentPerl  to get a performance
improvement from my CGI::App programs. It's very easy to set up and does
give me a huge performance improvement, although a lot of that is due to
having to load up the Class::DBI classes on startup.

Once you install PersisentPerl from CPAN, all you need to do is change
the path to perl in your instance script, eg:

change
#!/usr/bin/perl

to
#!/usr/bin/perperl

You can also play around with some of the PPerl options to group your
processes and share memory and also get the processes to die after a
period of being idle.

Like all persistent environments you do need to be careful that your
variables are scoped correctly.

Regards,

David



Prakash Inuganti -X (pinugant - Digital-X, Inc. at Cisco) wrote:
> Hi,
>
> As my client requested for a performance improvement of my Application,
> I thought FastCGI would help and I tried a couple of ways. Its not that
> I think performance is bad, but even if I can get a couple of seconds
> improvement and prove it, that would make my client happier.  First
> thing I tried was to use CGI::Application::FastCGI. But I cannot seem to
> go past login page. My code snippet is below. I defined 'rm' value as
> 'authenticate' in html template, but the Application is not able to move
> forward from Login page. When I click on Submit button on Login Page, it
> refreshes showing Login page again. Not able to access authenticate sub
> routine. Am I missing a trick here?
> If I change use base qw(CGI::Application::FastCGI); to use base
> qw(CGI::Application); everything works fine.
>
>
> Login.tmpl
>
>  <html>
>       <body>
>       <form name=login method=post>
> 	<table>
> 	<tr>
>             <td ><label for="UserId">User ID</label>
> </td><td>&nbsp;&nbsp;<input name="user" id="UserId" type="text"
> value="<TMPL_VAR NAME
> ="USER">" maxlength=8></td>
>           </tr>
>           <tr>
>             <td><label for="password">Password</label>
> </td><td>&nbsp;&nbsp;<input name="password" id="password"
> type="password" value="<TMPL_VAR NAME="PASSWORD">"></td>
>           </tr>
>           <tr>
>             <td colspan = 2>
>               <input  type="reset" name="Reset" value="Reset">
> &nbsp;&nbsp;
>               <input type="submit" name="Submit" value="Submit">
>             </td>
>           </tr>
>         </table>
>         <input type=hidden name=rm value=authenticate>
>        </form>
>        </body>
> </html>
>
> Base.pm
>
> use base qw(CGI::Application::FastCGI);
>
> sub cgiapp_init {
>         my($self) = shift;
>
>         my $db = new Db();
>
>         $self->session_config(
>                         CGI_SESSION_OPTIONS => ["driver:File",
> $self->query, {Directory => "$::LOG"}],
>                         COOKIE_PARAMS       => {-expires => '+24h',},
>                         SEND_COOKIE         => 1);
>
>         if(!$self->session->param('~logged-in') ) {
> 	$self->session->param('rm_restrict',
>             {'Administrator' => [qw(all)],
>              'Other'      => [qw(login authenticate home )]};
>                  
>         }
>         $self->param('rm_restrict' =>
> $self->session->param('rm_restrict'));
> }
>
> sub cgiapp_prerun {
>   my($self) = shift;
>   my $rm_restrict = $self->param('rm_restrict');
>   
>   # Redirect to login, if necessary
>
>   my $current_mode = $self->get_current_runmode();
>   
>   if(!$self->session->param('~logged-in') && ($current_mode ne
> 'authenticate'))
>  {
>     $self->prerun_mode('login');
>   }
>   $self->session->expire('~logged-in' => '+1h');
>   if (grep /^all$/, @{$$rm_restrict{$role}}) {
>     #no restriction
>   }else {
>      my $run_mode = $self->get_current_runmode();
>     if (! grep /$run_mode/, @{$$rm_restrict{$role}}) {
>       #show error page
>     }
>   }
> }
>
> Application.pm
>
> use strict;
> use base 'Base';
>
> sub setup {
>   my $self = shift;
>   $self->start_mode('login');
>   $self->mode_param('rm');
>   
>   $self->run_modes(
>               'login'                   => 'show_login',
>               'authenticate'            => 'authenticate',
>               'home'                    => 'show_home',
> 	);
>
> Instance.pl
>
> Use Application;
>
> my $app = Application->new();
> $app->run();
>
> The second Approach I took was to change instance script as below but it
> did not seem to matter. No gain in performance at all.
>
> Use FCGI;
> Use Application;
>
> while(FCGI::accept() >= 0){
>    my $app = Application->new();
>    $app->run();
> }
>
> Can you provide some help on using this FastCGI? Please let me know if
> any detail is not clear. Thanks in advance for your help.
>
>
> Thanks
> Prakash
>
>
>   

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.