Solved

Internal Server Error, occasionally

Posted on 2004-09-02
16
403 Views
Last Modified: 2010-03-04
Occasionally my web site delivers the "Internal Server Error" web page rather than delivering the output of the appropriate Perl script. This tends to happen after the page has been reloaded a few times, but there doesn't seem to be much consistency in when it fails. When it does fail (ie. deliver the Internal Server Error message), then an entry like the following appears in Apache's error.log file:

[Fri Sep  3 02:08:02 2004] [error] Undefined subroutine &Apache::ROOT::index_2ecgi::header called at /var/www/index.cgi line 6.\n

"index_2ecgi" presumable refers to "index.cgi", which is the page requested.
"header" is the name of a subroutine called on line 6 of index.cgi.

I have no idea why callilng the header subroutine is problematic sometimes and not others. Any suggestions as to how I can continue to debug this problem would be appreciated. If your willing to take a look at the web site,  this is the address: http://metagloss.gotdns.com. After clicking on a couple of links or reloading a few times the failure usually occurs.

Thanks for your help.
0
Comment
Question by:bobwood2000
  • 7
  • 5
  • 3
  • +1
16 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11969956
Hi

Ah, well, actually, nothing happened for me on the refresh (Mozilla Firefox) but the links were problematic. In most cases, Internal Server Error 500 is actually caused by faulty server-side programming, namely your Perl script. Is it possible to post your code?

Regards,
Zyloch
0
 
LVL 2

Expert Comment

by:brozzis
ID: 11970845

Any error could happen, too many processes, too many files open.
The result is always a Internal Server Error 500.

I'd give a chance to mod_perl, use it instead of a 'standard' cgi-bin script to reduce server side spawning.
I'm confident it will solve your problem, if your script is not buggy ;-)
0
 
LVL 15

Expert Comment

by:samri
ID: 11971295
perhaps you could monitor your server (OS, CPU, memort, and such), to see a patter?  I would agree with both of brozzis and Zyloch, that it could be with the PERL code and the machine (overloaded?)
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 15

Expert Comment

by:samri
ID: 11971297
it's apache 1.3.3 (just strike an error).

any chance to upgrade to 2.x (which most people said more robust) ??
0
 

Author Comment

by:bobwood2000
ID: 11973351
It looks like my problem is caused by my Perl code.

The script immediately below runs fine. It is displayed at http://metagloss.gotdns.com/test.cgi

----------test_working.cgi is below--------------------------------------------

&header;
print 'this is the body of a very simple script.';
&footer;


sub header
{

        print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                <html><head><style type="text/css"></style>
                <title>MetaGloss.org</title>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
                <meta name="keywords" content="glossary">
                <meta http-equiv="expires" content="0">
                </head><br><br>
                <body bgcolor="#eeeeee" marginwidth="0" marginheight="0" leftmargin="0"
                topmargin="0" text="#000000" link="000066" vlink="000066">

                <a name="top"></a><center>
                <table width=843px height=500px cellpadding=0 border=0>
                <tr><td bgcolor="#ffffff" valign=center align=center>
                <table border=0 width=100% height=100% cellpadding=0>
                <tr><td height=10% width=10% bgcolor="#ffffff" colspan=2><center>
                <img src="/images/metagloss5.jpg"></center></td></tr>

                <tr><td width=15% bgcolor="#bbbbbb">
                &nbsp;&nbsp;<a href=about.cgi>about</a><br><br>
                &nbsp;&nbsp;<a href=statistics.cgi>statistics</a><br><br>
                &nbsp;&nbsp;<a href=submit.cgi>submit</a><br><br>
                &nbsp;&nbsp;<a href=help.cgi>help</a><br><br>
                &nbsp;&nbsp;<a href=contact.cgi>contact</a>
                <br><br><br><br><br></td><td bgcolor="#dddddd">';

}



sub footer
{

        print '<center><br><br><br>
                <img src="/images/cat1.gif">
                </td></tr></table></body></html>';

}


------------------------------------------------------


However, this similar script often (but not always) delivers internal server errors. The only difference is that the "header" and "footer" functions are moved to a module called "common.pm", and then included in the primary script via the "use" statement.


----------------------test_failure.cgi is below--------------------------------

use common;

&header;
print 'this is the body of a very simple script.';
&footer;

----------------common.pm is below--------------------------------------

#! /usr/bin/perl

return 1;

sub header
{

print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><style type="text/css"></style>
<title>MetaGloss.org</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="glossary">
<meta http-equiv="expires" content="0">
</head><br><br>
<body bgcolor="#eeeeee" marginwidth="0" marginheight="0" leftmargin="0"
        topmargin="0" text="#000000" link="000066" vlink="000066">

<a name="top"></a><center>
<table width=843px height=500px cellpadding=0 border=0>
<tr><td bgcolor="#ffffff" valign=center align=center>
<table border=0 width=100% height=100% cellpadding=0>
<tr><td height=10% width=10% bgcolor="#ffffff" colspan=2><center>
        <img src="/images/metagloss5.jpg"></center></td></tr>

<tr><td width=15% bgcolor="#bbbbbb">
&nbsp;&nbsp;<a href=about.cgi>about</a><br><br>
&nbsp;&nbsp;<a href=statistics.cgi>statistics</a><br><br>
&nbsp;&nbsp;<a href=submit.cgi>submit</a><br><br>
&nbsp;&nbsp;<a href=help.cgi>help</a><br><br>
&nbsp;&nbsp;<a href=contact.cgi>contact</a>
<br><br><br><br><br></td><td bgcolor="#dddddd">';

}



sub footer
{

print '<center><br><br><br>
<img src="/images/cat1.gif">
</td></tr></table></body></html>';

}


------------------------------------------------------

0
 

Author Comment

by:bobwood2000
ID: 11973431
Here is the link to the first script. This is the working script. It contains the "header" and "footer" functions within the same file as the calls to these functions:
http://metagloss.gotdns.com/test_working.cgi

This is a link to the second script. It usually delivers internal server errors. It is equivalent to the first script, except that "header" and "footer" functions have been moved to a second file named "common.pm". "common.pm" is included in "test_failure.cgi" by a "use" statement.
http://metagloss.gotdns.com/test_failure.cgi
0
 
LVL 15

Expert Comment

by:samri
ID: 11973719
I would suspect that there is extra stuff sent to the browser before the standard

Content-type: text/html

Try to run your code from a shell promt, and note the output.   The above HTTP header should be sent out first (if the output is to be treated as HTML by the browser).  

In this case, I would suspect that the want the common.pm is written, or the way it is called may have cause the problem.

I typically stuff all of my common stuff in a file called common.pl, and use the statement "require common.pl;" in my code.  Works pretty much fine.

By putting the code in a .pm file, which I assume that is the extension for "Perl Module", and with my limited perl knowledge, I think that perl module needs to be in certain "format", so they could be called by "Use" statement.

Check if the code runs from command line first.
0
 
LVL 15

Expert Comment

by:samri
ID: 11973772
>> [Fri Sep  3 02:08:02 2004] [error] Undefined subroutine &Apache::ROOT::index_2ecgi::header called at /var/www/index.cgi line 6.\n

I think the error message indicate that there is a problem with subroutine call in Perl.
0
 

Author Comment

by:bobwood2000
ID: 11973789
Both test_working.cgi and test_failure.cgi run fine from the command line.
0
 
LVL 15

Expert Comment

by:samri
ID: 11973873
hi Bob,

I am sorry, but when you mentioned fine, meaning that the header is printed fine on the screen, immediately on the next line, or there is a blank line.

Example
-------------------
C:\Program Files\Apache Group\Apache2\cgi-bin>perl printenv.pl <--- this is where I hit enter
Content-type: text/plain                                                             <--- this is the immediate line

- same thing here.
C:\Program Files\Apache Group\Apache2\cgi-bin>cachemgr.cgi
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:
g/TR/html4/loose.dtd">
--
0
 

Author Comment

by:bobwood2000
ID: 11973882
>> I think the error message indicate that there is a problem with subroutine call in Perl.

I agree. Would it be better for me to include common.pm with the "require" statement rather the "use" statement?
0
 
LVL 15

Expert Comment

by:samri
ID: 11974004
hi bob,
again, I need to emphasize my weakness in perl.

To my knowledge, if you were to use require statement, the code will be "included" in your current code, at the point of insertion (where the require statement).  So, with my code,

--- my simple hello.cgi
#! perl

require "commmon.pl";

&print_html_header;
print "Helo world<br>";
&print_html_footer;
---
--- common.pl

sub print_html_header {
  print "Content-Type\: text\/html\n\n";
}

sub print_html_footer {
  print "Content-Type\: text\/html\n\n";
}

1;
---
Note the last "1;", it needs to be there.  Why?  reread my confession on Perl :)

So in this case, everything in common.pl, will be inserted in your hello.cgi, such that, in the actual execution, your helo.cgi becomes;

#! perl

sub print_html_header {
  print "Content-Type\: text\/html\n\n";
}

sub print_html_footer {
  print "Content-Type\: text\/html\n\n";
}

&print_html_header;
print "Helo world<br>";
&print_html_footer;
sub print_html_header {
  print "Content-Type\: text\/html\n\n";
}
--

however, in perl module programming (those file that has .pm extension inperl), they had a bunch of other requirement , which doesn;t make much sense to me :(
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 500 total points
ID: 11976038
Er... well, your common.pl isn't saved as a module, meaning with a .pm extension, so if you call it with use common, it will automatically assume use common.pm. Try use common.pl, or better, change your common.pl to common.pm and have this code in it:


package common;

BEGIN {
   use Exporter();
   @ISA=qw(Exporter);
   @EXPORT = qw(&print_html_header &print_html_footer);
}

sub print_html_header {
  print "Content-Type\: text\/html\n\n";
}

sub print_html_footer {
  print "Content-Type\: text\/html\n\n";
}

return 1;

END {
}

Now, you can call it by doing use common;
and then use it in your file like &print_html_header
0
 

Author Comment

by:bobwood2000
ID: 11977815
Woo hoo! Problem solved. I added Zyloch's code to common.pm, and then made all my files part of the same package. AFter 3 days of debugging, the web site is finally working. :-)

Thank you all very much.
0
 
LVL 15

Expert Comment

by:samri
ID: 11980367
Zyloch: Cool... is that simple?  gee..

0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11980700
Heh, you probably just missed it--happens to me sometimes too
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question