Solved

Internal Server Error, occasionally

Posted on 2004-09-02
16
396 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now