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

I have a Perl script that outputs a graph created by GD to a webpage. You specifiy the info by selecting a column name in a database, then it generates the graph on the fly. It works great, except that after running the program 3-4 times it stops working and says that webdb.cgi printed nothing. When I run it from the command line, its okay and no syntax errors. But when it tries to run from the web, it doesn't work. None of the other methods work either, even if its not trying to draw the graph. Is this a problem with my web server (which is Personal Web Server) or my program?
Thanks, Kevin

Replies are listed 'Best First'.
Re: GD module stops working
by Jouke (Curate) on Jul 23, 2001 at 23:57 UTC
    There is no-one who could give a sensible answer to your question with this little information. Your title is that the GD module stops working. I find that hard to believe.

    I think it would be best if you'd post the code, the exact errormessage and the perlversion you are using.

    Jouke Visser, Perl 'Adept'
    Using Perl to help the disabled: pVoice and pStory
Re: GD module stops working
by ChemBoy (Priest) on Jul 24, 2001 at 00:12 UTC

    As Jouke says, it's hard to diagnose a problem with code we can't see, but you might try adding use CGI::Carp 'fatalsToBrowser'; to the beginning of your program, to see if the script is dying with an error message you can't see.

    If that doesn't tell you the answer, then you should indeed try posting the offending code, so we can try to help you debug it.



    If God had meant us to fly, he would *never* have give us the railroads.
        --Michael Flanders

Re: GD module stops working
by kbradford (Novice) on Jul 24, 2001 at 15:59 UTC
    I'll try to give some more info. Perl version is 5.6.1, build 626 from Activestate. I am running PWS v4, build 1381. The new code that seems to make my program crash after being run about 4 times:

    use GD; use GD::Graph; use GD::Graph::lines; use GD::Graph::pie; use GD::Graph::bars; use GD::Graph::colour; $field = $inputs{"field"}; $query = "SELECT $field FROM system_info"; print "<font size=-1>Query performed: $query<p>"; ## BEGIN DB ACCESS ## # Make a database handle $dbh = DBI->connect('dbi:Oracle:server', 'username', 'pass',) || d +ie "Database connection not made $DBI::errstr"; # Make a statement handle $sth = $dbh->prepare($query); $sth->execute; $i=0; while (@data=$sth->fetchrow_array()) { @array[$i]=$data[0]; $i++; } # Sort the array @array = sort {$a cmp $b} @array; $a=0; $b=0; $array_length = scalar(@array); print "Generating a graph for $array_length machines. Please wait +..."; # Create an associative array for all entries and the number of ti +mes in database while ($a < $array_length) { $b = $a + 1; if ($array[$a] =~ $array[$b]) { $count{$array[$a]}++; } $a++; } #### Start Graph Stuff @keys = keys(%count); @values = values(%count); @graphdata = ([@keys],[@values]); $num_graph_columns = scalar (@keys); $width=$num_graph_columns * 30; if ($width < 450) { $width=450; } $graph = GD::Graph::bars->new($width, 500); $graph->set( x_label => "$field", y_label => "number", title => "Graph of $field", bar_spacing => 6, shadow_depth => 4, shadowclr => 'dred', transparent => '1', x_labels_vertical => '1', show_values => '1' ); $graph->set_title_font('C:/winnt/fonts/arial.ttf', 18); $graph->set_x_axis_font('C:/winnt/fonts/arial.ttf', 8); $graph->set_y_axis_font('C:/winnt/fonts/arial.ttf', 8); $graph->set_y_label_font('C:/winnt/fonts/arial.ttf', 12); $graph->set_x_label_font('C:/winnt/fonts/arial.ttf', 12); $graph->plot(\@graphdata); open(OUTPUT, ">../wwwroot/chart.jpg") or die "Can't open chart.jpg +: $!\n"; binmode OUTPUT; print OUTPUT $graph->gd->jpeg(); close(OUTPUT); print "<p><center><img src=../chart.jpg><BR><BR><BR><font size=-2> +<table border=1 width=25%>"; foreach (keys(%count)) { print "<tr><td><font size=-1>$_</td><td><font size=-1>$count{$ +_}</td></tr>"; } print "</font></table>";
    This code works, and I can display 4 or 5 graphs, but then the entire program stops responding. No error messages except: 'C:\Inetpub\scripts\webdb.cgi' script produced no output

    If run from the command line the program runs correctly, with no errors. However, when run from the command line it never calls this method. It just checks the syntax. Any ideas?
    Thanks, Kevin

      It's still very hard to make sensible comments, but I'll give it a try:
      • First piece of advice: add  use strict; at the top of your script, and add -w after the shebang (#!).
      • I get the feeling something is missing from the beginning, since you're starting with $field = $inputs{"field"};
      • You say that it dies without doing anything. That means it does not reach the part where you're creating the graphs themselves, since that's the first unconditional 'print' you're using (print "Generating a graph for $array_length machines.  Please wait...";)
      • This means your script probably has a problem with the connection to the Oracle database. Could it be that your database is very busy? Could it be that the response from the database is so slow that the script times out? Could it be you're receiving so much data that it takes too long for the data to arrive that PWS eventually kills the CGI script?
      Just my EUR 0.02.

      Jouke Visser, Perl 'Adept'
      Using Perl to help the disabled: pVoice and pStory
        Thanks for your advice Jouke. I don't think it has to do with the Oracle connection. I'm beginning to think that it is my web server. The graphs will display about 5 times, then on the 6th it will display Generating a graph for $array_length machines. Please wait... and it will appear to be loading the image and then stops loading the page. Then, no cgi scripts will work. Even other scripts that do not attempt to access the database won't load. Its as if the web server does not want to process any cgi scripts. Currently I have my registry pointing to perlis.dll, I might change it to perl.exe %s. It will be slower, but maybe it will work. And yes, there was some crap before the part of the code I posted, but nothing other than some beginning crap to get variables and print html headers.

        Thanks, Kevin

Re: GD module stops working
by kbradford (Novice) on Jul 24, 2001 at 16:04 UTC
    Also, adding the fatals to browser did not display any error message. The only current way to fix the problem is to reboot. Kevin