zetetes has asked for the wisdom of the Perl Monks concerning the following question:

i'm having a strange problem over here.
while the following code does properly work on my localhost (while developing), the 'real' host hangs itself up.
i thought it could be something wrong with the select-statement, yet all the other statements do work fine.
it could be something with the amount of the returned rows. < 20 rows do work fine, >20 only 'sometimes'.

what am i asking you for? could any expert monk out there (maybe it doesn't even take an expert) tell me if there's something wrong with the code? and/or what else could be the problem that it works fine on my localhost, but not 'over the net'? could something be wrong with the foreach? do i eat up the memory? i do not know.

the code does the following:
printing a dropdown with the available elements on the database. if you select one, it reads only this element and shows the content in a simple web-form (not shown here).
my ($head, $where, $titel, $text, $titel_e, $text_e, $url, $type); my @update; my @elementlist = Statements::doSelect("element_id,element_titel","t +_element"); print qq( <form action="$Constants::cgi/admin.pl?act=1" method="POST"> <select name="eid" onChange="submit()"> <option value="">Neues Element einf\374gen</option> ); foreach my $foo (0..$#elementlist) { my $selected; if ($list{'eid'} == $elementlist[$foo][0]) { $selected = "selected"; } print qq( <option value="$elementlist[$foo][0]" $selected>$elementlist +[$foo][1]</option> ); } print qq( </select><br/> ); if ($list{'eid'}) { $where = "element_id = $list{'eid'}"; @update = Statements::doSelect("element_id,element_titel,element +_text,element_titel_e,element_text_e,URL,element_type","t_element",$w +here); ($titel, $text, $titel_e, $text_e, $url, $type) = ($update[0][1] +,$update[0][2],$update[0][3],$update[0][4],$update[0][5],$update[0][6 +]); $head = "$titel ändern"; } else { $head = "Neues Element einfügen"; }

thank you guys.

update:
i post the code of the doSelect-function, since that's the piece which sets up the sql-statement.
# ----------------------------------------------------------------- # Name : doSelect(). # Description : select values from db # Recieves : SELECT, FROM, WHERE, ORDER, GROUP # Returns : selected values # ----------------------------------------------------------------- sub doSelect { my (@res, @row, $i); my ($select, $from,$where,$group,$order); $select = "SELECT $_[0] "; $from = "FROM $_[1] "; if ($_[2]) { $where = "WHERE $_[2] "; } if ($_[3]) { $group = "GROUP BY $_[3] "; } if ($_[4]) { $order = "ORDER BY $_[4] "; } my $sql = $select . $from . $where . $group . $order; #print $sql; my $sth = DBKomm::connectdb($Constants::dbsrc,$Constants::dbuser,$Cons +tants::dbpasswd)->prepare( $sql ); if ($sth) { $sth->execute; while (my @row = $sth->fetchrow_array) { $res[$i++] = [@row]; } $sth->finish; } else { print "nothing here to do and say"; } DBKomm::disconnectdb(); return @res; }

Replies are listed 'Best First'.
Re: host does not respond; sometimes
by superfrink (Curate) on Aug 28, 2004 at 22:19 UTC
    This comment is on not about your perl code but I have had a similar problem in the past. In my case it was due to someone putting machines which were on different subnets on the same ethernet switch and they were using the same gateway. The sql server was on one subnet and the perl was running on a machine on the other.

    Short connections worked but longer connections flaked out. It turns out it was related to something realizing it could shortcut the route between the machines. It didn't work though because the routing tables on the end machines were not setup for that route. (The gateway was OpenBSD and the end machines were Linux, I don't recall the versions.)

    PS: I don't know exactly what I'm talking about here but telling the Linux servers to ignore ICMP redirects seemed to make the problem go away.
      uhoh. as far as i know the hoster, this 'could' be possible. but honestly i do not have a clue. is there something I could do to solve that 'issue' or is the only way to solve it at the hosters place?
Re: host does not respond; sometimes
by PodMaster (Abbot) on Aug 29, 2004 at 12:47 UTC
    That code is incomplete. How about you find out where the progam hangs itself? How you say? Like this
    open LOG, '>', '/some/place/my.log' or die $!; ... print LOG q~About to my @elementlist = Statements::doSelect at ~, __FI +LE__, ' ', __LINE__,"\n"; my @elementlist = Statements::doSelect("element_id,element_titel","t_e +lement"); print LOG "DONE \n"; ...
    update: Once you find where the program hangs, examine what its doing very closely (and if you want our help, well, post all the relevant code, any error messages, sample input/output ... ).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      since i do not have access to the error_logs and am not that much of an experienced perlcoder, i asked you guys, if there is a mistake in that code. i only posted that code because the problem must be on those few lines. i am definitely not asking you to solve my problems, that'd be too easy. i am asking you for some guidance on my very own seek to (perl-)wisdom.

      but well, you're definitely right, having a look at the error_log would be very helpful, so i am organizing to get access to them.

      do you say, the code is incomplete, becaus i did not post the rest of the script or because something is missing *at* the code i posted?

      as always: thank you for every little piece of thought on that.
        but well, you're definitely right, having a look at the error_log would be very helpful, so i am organizing to get access to them.
        I just showed you how to keep your own log, so you can pinpoint exactly which statement is causing your application to hang. In CGI enviroment, during development, you'll also want to redirect STDERR with CGI::Carp's carpout, like
        BEGIN { use CGI::Carp qw(carpout); open(LOG, ">>/usr/local/cgi-logs/mycgi-log") or die("Unable to open mycgi-log: $!\n"); carpout(LOG); }
        CGI Help Guide (among others) in Tutorials for more tips.
         
        do you say, the code is incomplete, becaus i did not post the rest of the script or because something is missing *at* the code i posted?
        I say its incomplete (even after your update) because Statements::doSelect and DBKomm::connectdb only exist on your computer.

        If it is your database communication to blame, well, only you can help yourself. If you are using DBI ($sth is a hint that you may be, but I can't tell), I'd say make sure you RaiseError => 1 when you connect, and if that doesn't give you any insight, turn on trace (see DBI_TRACE in the DBI documentation), but like I said, I don't know what you're using.

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.