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

[cgiapp] Help using FastCGI


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


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