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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about constants, db pulls and sessions...my site seems to be crashing...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
ok. i already knew that i write horrible, non-efficient code...that being said, i need to figure out something.

i use this to store db information and call it later down the line to use that stored info:

Code:
$query1="SELECT value1, value2 from mytable WHERE conditionX = '100' limit 1";
$sth1 = $dbh->prepare($query1);
}

 $sth1->execute;
 use constant VAL1 => 0;
 use constant VAL2 => 1;

  while (@row = $sth1->fetchrow_array() ){
  $v1 = $row[VAL1];
  $v2 = $row[VAL2];
  }

everything was cool up until my hosting company updated their servers, not sure if it's related or pure coincidence, but now i'm getting these errors:

##
Constant subroutine main::VAL1 redefined at /usr/local/lib/perl5/5.8.8/constant.pm line 103.
Constant subroutine main::VAL2 redefined at /usr/local/lib/perl5/5.8.8/constant.pm line 103.
##

i get intermittent 500 errors, and then the site will work again. the tech at the hosting company suggested that the redefining "hiccups" were causing the 500 errors, then recompiling, which may explain why the site "corrects" itself.

i'm thinking that before the updating of servers, my inefficient code was okay, but after update the inefficiency became a sore thumb, so to speak.

as if that wasn't enough, i also am getting this error in the log, at the same or close to same time as the other errors.

##
Can't call method "id" on an undefined value at /home/users/web/xxxx/xxxxxxx/myfile.cgi line 6.
##

where the "id" they are referring to is this:

Code:
#!/usr/bin/perl
use CGI::Session;

$sid = $cgi->cookie("CGISESSID") || undef;
$session = new CGI::Session(undef, $sid, {Directory=>'\tmp'});
$cookie = $cgi->cookie(CGISESSID => $session->id);
$sSid = $session->id();

at first, i thought the entire error was due to some server side session module failure, since i saw that error first, but now i'm thinking that if the tech is correct, and the redefining constant issue is giving me the 500 error and the session issue is getting caught up in the server downtime, because when the site comes back online, the session id persists through the error.

i'm hoping to figure this out, and more importantly, gain a better understanding of perl and how/why the old way i was doing it wasn't the correct way.

just for clarification, i learned how to use the constants from a perl book, just following the examples in the book.

thanks!

- g


 
Constants in perl are implemented as functions and as such are inherently global. You should declare them at top level, but of course there's no advantage in using constants if their value is used only once.
I suppose there was an upgrade of perl and the new version was stricter in error checking, but really don't know.
Don't know either on the id problem.

: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top