Using CGI and GD modules

J

James

test.cgi script shown below is adapted from the "CGI programming" book
(chap.13).
There's no problem with installation of GD module and generation of PNG
file.
However, on the web, it gives the following error.

Is this a script error, or apache2 configuration error?

============================

Server error!

The server encountered an internal error and was unable to complete
your request.

Error message:
Premature end of script headers: test.cgi

============================
$ cat test.cgi

use CGI;
use GD::Graph::bars;

$cgi = new CGI;
$g = new GD::Graph::bars;

@data = ( [qw(A B C D E F)], [qw(1 2 3 4 5 6)] );

$g->set(
x_label => 'X',
y_label => 'Y',
title => 'TITLE',
show_values => \@data
);

$graph = $g->plot(\@data);

print $cgi->header( -type => 'image/png', -expires => '-1d' );

binmode STDOUT;

print $graph->png;
============================

Any help would be greatly appreciated.

James
 
B

Bengt-Arne Fjellner

James said:
test.cgi script shown below is adapted from the "CGI programming" book
(chap.13).
There's no problem with installation of GD module and generation of PNG
file.
However, on the web, it gives the following error.

Is this a script error, or apache2 configuration error?

============================

Server error!

The server encountered an internal error and was unable to complete
your request.

Error message:
Premature end of script headers: test.cgi

============================
$ cat test.cgi

#! /usr/bin/perl # or whereever your perl is.
#also
use warnings; # always good to have
use CGI;
use GD::Graph::bars;

$cgi = new CGI;
$g = new GD::Graph::bars;

@data = ( [qw(A B C D E F)], [qw(1 2 3 4 5 6)] );

$g->set(
x_label => 'X',
y_label => 'Y',
title => 'TITLE',
show_values => \@data
);

$graph = $g->plot(\@data);

print $cgi->header( -type => 'image/png', -expires => '-1d' );

binmode STDOUT;

print $graph->png;
============================

Any help would be greatly appreciated.

James
 
S

Sherm Pendley

James said:
test.cgi script shown below is adapted from the "CGI programming" book
(chap.13).
There's no problem with installation of GD module and generation of PNG
file.
However, on the web, it gives the following error.

Is this a script error, or apache2 configuration error?

The FAQ has a link to some good troubleshooting tips:

perldoc -q 500

The first and most obvious thing to do is to get a better error message.

Look in your server's error log. That's where you'll find the error message
that was actually printed by Perl; the message you see in your browser is
just the server complaining that it received Perl's error message instead
of the CGI headers that it expected.

You should also add this to your script, immediately after "use CGI;":

use CGI::Carp qw(fatalsToBrowser);

If the server has CGI::Carp available - and it should, it's a core module in
recent Perls - that will result in a more-informative error page instead of
the generic one you see now.

sherm--
 
J

James

Sherm said:
Look in your server's error log. That's where you'll find the error message
that was actually printed by Perl; the message you see in your browser is
just the server complaining that it received Perl's error message instead
of the CGI headers that it expected.

Thanks for the advice.
I could resolve the problem with the error log.

Can't load
'/usr/local/lib/perl5/site_perl/5.8.7/sun4-solaris/auto/GD/GD.so' for
module GD: ld.so.1: fatal: libgcc_s.so.1: open failed: No such file or
directory at /usr/local/lib/perl5/5.8.7/sun4-solaris/DynaLoader.pm line
230.

The gcc compiler (ver 3.X) needs this libgcc_s.so.1 file in
/usr/local/lib, which is not
in the default runtime library paths for the CGI script.


James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top