SpeedyCGI is very easy and powerful speedup the response and execute perl scripts.
also some scripts changed only first line.
#!/usr/bin/perl
↓
#!/usr/bin/speedy
only that.
but there are some important things to use it.
because SpeedyCGI running deamon untill the timeout. (default timeout is set to 3600sec = 1hour).
so sometimes SpeedyCGI needs initialize variables.
it means, GET, POST method post the input values to CGI. Like a messages and user name, Id and Pass...
There values set by manually, then there are problem to use SpeedyCGI.
#!/usr/bin/speedy -- -t300 -M2
use strict;
use vars qw($GLOBAL $FUNCGLOBAL %FORM);
print "Content-type: text/plain\r\n\r\n";
my $test=scalar localtime time;
{
my $local;
$local++;
$GLOBAL++;
&func($FUNCGLOBAL);
{
my ($name, $value, $buffer);
if ($ENV{'REQUEST_METHOD'} eq "POST"){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}else{
$buffer = $ENV{'QUERY_STRING'};
}
foreach (split /&/,$buffer) {
($name, $value) = split /=/;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('H2',$1)/eg;
$value =~ s//>/g;
$value =~ s/"/"/g;
$value =~ tr/ / /s;
$FORM{$name} = $value;
}
}
print <<"_EOF_";
Result: $$
Global:\t$GLOBAL
Local:\t$local
FUNC:\t$FUNCGLOBAL
TEST:\t$test
FORM:
_EOF_
}
foreach(sort keys %FORM){ print "$_ = $FORM{$_}\n" }
sub func(){ $_[0]++; }running on that cgi on httpd, send query to that cgi. Like http://example.com/test.cgi?hoge=hoge Then the CGI output Like this:
Result: 20575
Global: 1
Local: 1
FUNC: 1
TEST: Fri Jul 23 03:04:13 2010
FORM:
hoge = hoge
Then request that cgi without query strings. Like http://example.com/test.cgi?
Result: 20575
Global: 2
Local: 1
FUNC: 2
TEST: Fri Jul 23 03:08:39 2010
FORM:
hoge = hoge
did you find out which line is strange?
Yes, "hoge = hoge" is strange!
I didn't send any queries :-(
But the output is there.
So when you change to the SpeedCGI from perl, be careful to use GLOBAL variables :)
use CGI, huh? I don't know perl modules :-p
No, just joke, I checked there is no problem with CGI.pm.