×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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


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

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.

http://www.xcalcs.com : Online engineering calculations
http://www.megamag.it : Magnetic brakes for fun rides
http://www.levitans.com : Air bearing pads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close