Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why Does my code take 30 sec's to process

Status
Not open for further replies.

madaxe

Technical User
Dec 21, 2004
44
0
0
US
Hi i have a sub that takes like 30 secs to run but i dont know why i have used the same sub in other cgi's and it runs instantly but this code takes ages i dont know why? code below:-

Code:
#!/Perl/bin/perl

use CGI;

################################################################################

if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
    @pairs = split(/&/, $ENV{'QUERY_STRING'});
}
else
{
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
}	
foreach $pair (@pairs) 
{
	($name, $value) = split(/=/, $pair);
	$value =~ tr/+/ /;
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	$FORM{$name} = $value;	
}

################################################################################

$loginname = $FORM{login_name};
$playeremail = $FORM{player_email};
$playerchar = $FORM{player_character};
$loginpass = $FORM{login_password};

$loginlist ="REMOVED FOR SESATIVITY";
$forward = "../usermng.html";

############################# Check Fields #####################################

if ($loginname eq "") {
	&error("a Login Name");
}
if ($playeremail eq "") {
	&error("an email address");
}
if ($playerchar eq "") {
	&error("a Player Character");
}
if ($loginpass eq "") {
	&error("a Player Password");
}
unless ($playeremail =~ m/\@/i) {
	&error("correct e-mail address");
}


############################ Write Info To File ###############################

if  (($loginname ne "") && ($loginpass ne "")) {


open(FILE, ">>$loginlist");
print FILE "$loginname\|$loginpass\|$playerchar\|$playeremail\n";
close(FILE);


print <<"htmlend";

print "<html><head><META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=$forward\"></head></html>\n";
print "<a href=\"$forward\">Click here to contine!</a>\n";

htmlend

}

############################# Sub Programmes ###################################

sub error {

local($error) = $_[0];
print <<"html";

<html>

<head><title>Error</title></head>

<body>
<center><font size=5>Error</font><p><b>You must enter $error!</center>
</body>

</html>
html
exit;
}
 
You have use CGI in there, but you're not using it. That shouldn't cause the problem though.

Have you tried printing debug statements to a log file to see if you can trace where the lag is occurring, is there a lot more data being passed to the page than what we're seeing here

--Paul

cigless ...
 
Hi Paul

Can you tell me how i print debug statements, i will remove the cgi at the top but i think you are right that it wont make much differance.

Marc

Madaxe
 
Code:
#!/Perl/bin/perl

use CGI;
[COLOR=red]open LOG ">logfile.txt";[/color]

################################################################################

print LOG localtime()." Starting\n";
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
[COLOR=red]    print LOG localtime()." starting Split query string\n";[/color]
    @pairs = split(/&/, $ENV{'QUERY_STRING'});
[COLOR=red]    print LOG localtime()." Split query string\n";[/color]
}
else
{
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);
}    
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;    
}

################################################################################

$loginname = $FORM{login_name};
$playeremail = $FORM{player_email};
$playerchar = $FORM{player_character};
$loginpass = $FORM{login_password};

$loginlist ="REMOVED FOR SESATIVITY";
$forward = "../usermng.html";

############################# Check Fields #####################################

if ($loginname eq "") {
    &error("a Login Name");
}
if ($playeremail eq "") {
    &error("an email address");
}
if ($playerchar eq "") {
    &error("a Player Character");
}
if ($loginpass eq "") {
    &error("a Player Password");
}
unless ($playeremail =~ m/\@/i) {
    &error("correct e-mail address");
}


############################ Write Info To File ###############################

if  (($loginname ne "") && ($loginpass ne "")) {


open(FILE, ">>$loginlist");
print FILE "$loginname\|$loginpass\|$playerchar\|$playeremail\n";
close(FILE);


print <<"htmlend";

print "<html><head><META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=$forward\"></head></html>\n";
print "<a href=\"$forward\">Click here to contine!</a>\n";

htmlend
[COLOR=red]close LOG;[/color]
}

############################# Sub Programmes ###################################

sub error {

local($error) = $_[0];
print <<"html";

<html>

<head><title>Error</title></head>

<body>
<center><font size=5>Error</font><p><b>You must enter $error!</center>
</body>

</html>
html

exit;
}

cigless ...
 
thanks paul i will try

Madaxe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top