INTERNAL SERVER ERROR (WIERD???)

Discussion in 'Perl Misc' started by wizard, Aug 31, 2005.

  1. wizard

    wizard Guest

    Hello Friends,
    Kindly help.
    I am working on an script which is working with our email program of
    our company.
    Recently some changes were made to the script and it started giving he
    nasty " 500 INTERNAL SERVER ERROR".
    The Apache error logs give:-
    Premature end of script headers.

    Now, the script does execute and the email is sent but the webpage
    gives the error. Also, this error comes up only sometimes but not
    everytime we run the script in identical conditions, say one in three
    times. Sometimes when I go back to the previous page and again press
    the submit button , it goes properly. All the file permissions are
    proper, the /usr/bin/perl -w is right, Content type is correct, pert
    -cwT , all are checked , I mean , all the usual answers to the problem
    are checked and they are fine. If it were a syntax error, or some
    header problem , it would never have run , but it is running well for
    the past 7 years. The changes that I made to it were nominal and they
    do not affect the output.

    Also, I dont know how to step run the script from a web browser. Also,
    I dont know where to look for the bug since it does run properly
    SOMETIMES.

    Please help.

    Regards,
    Vivek. J. Joshi.
     
    wizard, Aug 31, 2005
    #1
    1. Advertising

  2. wizard

    Matt Garrish Guest

    "wizard" <> wrote in message
    news:...
    > Hello Friends,
    > Kindly help.


    Why do you think cross-posting this same vague problem to
    comp.lang.perl.misc will be any more fruitful. Please see the
    recommendations I made to you in alt.perl and actually try them first.

    Matt
     
    Matt Garrish, Aug 31, 2005
    #2
    1. Advertising

  3. wizard

    Brian Wakem Guest

    wizard wrote:

    > Hello Friends,
    > Kindly help.
    > I am working on an script which is working with our email program of
    > our company.
    > Recently some changes were made to the script and it started giving he
    > nasty " 500 INTERNAL SERVER ERROR".
    > The Apache error logs give:-
    > Premature end of script headers.
    >
    > Now, the script does execute and the email is sent but the webpage
    > gives the error. Also, this error comes up only sometimes but not
    > everytime we run the script in identical conditions, say one in three
    > times. Sometimes when I go back to the previous page and again press
    > the submit button , it goes properly. All the file permissions are
    > proper, the /usr/bin/perl -w is right, Content type is correct, pert
    > -cwT , all are checked , I mean , all the usual answers to the problem
    > are checked and they are fine. If it were a syntax error, or some
    > header problem , it would never have run , but it is running well for
    > the past 7 years. The changes that I made to it were nominal and they
    > do not affect the output.
    >
    > Also, I dont know how to step run the script from a web browser. Also,
    > I dont know where to look for the bug since it does run properly
    > SOMETIMES.
    >
    > Please help.
    >
    > Regards,
    > Vivek. J. Joshi.




    use CGI::Carp qw(fatalsToBrowser);


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Aug 31, 2005
    #3
  4. wizard

    Paul Lalli Guest

    wizard wrote:

    > I am working on an script which is working with our email program of
    > our company.
    > Recently some changes were made to the script and it started giving he
    > nasty " 500 INTERNAL SERVER ERROR".
    > The Apache error logs give:-
    > Premature end of script headers.


    Is that the *last* message in the log, or the *only* message in the
    log?

    > Now, the script does execute and the email is sent but the webpage
    > gives the error. Also, this error comes up only sometimes but not
    > everytime we run the script in identical conditions, say one in three
    > times. Sometimes when I go back to the previous page and again press
    > the submit button , it goes properly. All the file permissions are
    > proper, the /usr/bin/perl -w is right, Content type is correct, pert
    > -cwT , all are checked , I mean , all the usual answers to the problem
    > are checked and they are fine. If it were a syntax error, or some
    > header problem , it would never have run ,


    Not true. Just because the CGI script doesn't return proper HTTP
    headers, doesn't mean that the other Perl code in the script can't run.

    > but it is running well for
    > the past 7 years. The changes that I made to it were nominal and they
    > do not affect the output.


    Says you. Perhaps you should tell us *what* changes you made, rather
    than just asking us to take your word for it...

    > Also, I dont know how to step run the script from a web browser. Also,
    > I dont know where to look for the bug since it does run properly
    > SOMETIMES.


    What are the results of the script when run via the command line? What
    is output? Are all the proper HTTP headers printed, in all possible
    executions of the script?

    Paul Lalli
     
    Paul Lalli, Aug 31, 2005
    #4
  5. wizard

    wizard Guest

    When the scripts are run via command line, the output is indeterminate
    because many of the cgi variables are given to the perl script at run
    time, and also it gets executed only if the cookies are correct, i.e.
    there are modules which check the cookies.
    As suggested to add the line :-
    use CGI::Carp qw(fatalsToBrowser);
    its already present.
    I am flushing the output using:-
    select(STDOUT); $| = 1; #autoflush
    if (FAXMAIL) { select(FAXMAIL); $| = 1; }
    The module which I have added is for adding attachments from the
    folders , which dosen't get executed because I dont attach anything.
    Its inside an If-condition. The last line in the Apache logs is:-
    Premature end of script headers in sm.e
    Also, if the syntax was not okay, it would never have got executed but
    it does get executed sometimes.
     
    wizard, Sep 1, 2005
    #5
  6. wizard

    Scott Bryce Guest

    wizard wrote:

    > When the scripts are run via command line, the output is
    > indeterminate because many of the cgi variables are given to the perl
    > script at run time,


    Hard code some values in and see what happens.


    > and also it gets executed only if the cookies are
    > correct, i.e. there are modules which check the cookies.


    Bypass the modules. Or hard code in some cookie values. Or have the
    module subroutines return meaningful values for testing purposes.


    > The last line in the Apache logs is:- Premature end of
    > script headers in sm.e


    Then you need to know what the script is printing for headers.

    I don't believe you have posted actual code. Take a look at the posting
    guidelines, them reduce your script to the shortest script that
    demonstrates the problem. Post that here. We can't help you with code we
    can't see.
     
    Scott Bryce, Sep 1, 2005
    #6
  7. wizard

    Brian Wakem Guest

    wizard wrote:

    > When the scripts are run via command line, the output is indeterminate
    > because many of the cgi variables are given to the perl script at run
    > time, and also it gets executed only if the cookies are correct, i.e.
    > there are modules which check the cookies.
    > As suggested to add the line :-
    > use CGI::Carp qw(fatalsToBrowser);
    > its already present.
    > I am flushing the output using:-
    > select(STDOUT); $| = 1; #autoflush
    > if (FAXMAIL) { select(FAXMAIL); $| = 1; }
    > The module which I have added is for adding attachments from the
    > folders , which dosen't get executed because I dont attach anything.
    > Its inside an If-condition. The last line in the Apache logs is:-
    > Premature end of script headers in sm.e
    > Also, if the syntax was not okay, it would never have got executed but
    > it does get executed sometimes.



    It sounds like the script may not be producing any output at all, therefore
    it runs but Apache returns an error as no header is output. Is the line
    that prints the header inside a conditional loop? or a subroutine that
    isn't guaranteed to run?

    You need to narrow down the error and post some code as we can only guess
    what the code consists of.



    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Sep 1, 2005
    #7
  8. wizard

    Juha Laiho Guest

    "wizard" <> said:
    >I am working on an script which is working with our email program of
    >our company.
    >Recently some changes were made to the script and it started giving he
    >nasty " 500 INTERNAL SERVER ERROR".
    >The Apache error logs give:-
    >Premature end of script headers.


    Bad guesses on badly stated problem;

    Could it be that some external program run by your script is in
    some cases producing some output before the script gets to send
    the HTTP headers?
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Sep 1, 2005
    #8
  9. wizard

    wizard Guest

    Hello friends,
    Thanks for your suggestions. I am posting some part of the code here. (
    The entire code is of more than 1500 lines ). I will mention the parts
    which are added. The old code still runs fine.

    The classes below are from both perl and C programs and are interfaced
    by SWIG.

    The modules used by the code:-

    use CGI::Carp qw(fatalsToBrowser);
    require 5.001;
    use POSIX qw(strftime);
    use perl_verify;
    use getinfo;
    use personal;
    use preference;
    use address;
    use signature;
    use misc;
    use bcase; #### added ####
    require "cgi-lib.pl";

    The added part:-
    #get_briefcase_home_dir(BRIEFCASE_ROOT_DIR, domain_name,
    which_dot(domain_name));
    $dot = &bcase::which_dot($mydomain);
    $bcase_root_dir="";
    $bcase_home_dir=&bcase::get_briefcase_home_dir($bcase_root_dir,$mydomain,$dot);


    The files are opened and conditions are checked here:- (present even
    earlier, but posting for o/p flushing):-

    #if ($#mailtothese>=0 || $#mailccthese>=0 || $#mailbccthese>=0 ||
    $toallusers) { #send an email, call 'sendmail'
    if ($#mailtothese>=0 || $#mailccthese>=0 || $#mailbccthese>=0) { #send
    an email, call 'sendmail'
    $receipt = "";
    if (defined($cgi_data{'rr'})) {
    $receipt = "-N failure,delay,success";
    }
    if (!open(MAIL,"|$mailprog -oem -i -R hdrs -f$from -t $receipt >
    /dev/null 2> /dev/null")) {
    $sendmailerr = 1;
    }
    }

    $read_receipt = "";
    if (defined($cgi_data{'mdn'})) {
    $read_receipt = "Disposition-Notification-To: $from\n";
    }

    if (defined($cgi_data{'sv'}) and $cgi_data{'sv'} eq 'yes') { #save a
    copy? must send a different mail
    open(MAILME,"|$mailprog -oem -i -R hdrs -f$from $from > /dev/null
    2> /dev/null");
    }

    ( other file descriptors are also initialized and operated upon in the
    same war ).

    select(STDOUT); $| = 1; #autoflush
    if (FAXMAIL) { select(FAXMAIL); $| = 1; }
    if (MAILALL) { select(MAILALL); $| = 1; }
    if (MAIL) { select(MAIL); $| = 1; }
    if (MAILME) { select(MAILME); $| = 1; }

    Here's how the o/p is sent through sendmail:-

    if (MAIL) {
    print MAIL <<_TO_END_;
    X-Originating-IP: $ENV{'REMOTE_ADDR'}
    Reply-To: $fullname <$replytoemail>
    From: $fullname <$from>
    _TO_END_
    }

    Some added lines:-

    #attach the number of files from Web Folders here
    #@afarray;
    #$nooffiles;
    $nooffiles=0;
    $wflist=$cgi_data{'filelist'};
    if ($wflist ne ""){
    @afarray=split(/,/,$wflist);
    $nooffiles=scalar(@afarray);

    $len = $ENV{'CONTENT_LENGTH'};
    my $attach_file_size=0;
    #&CgiError($cgi_lib'maxdata);
    #my $fname=$bcase_home_dir . "/" . $f1;
    #check for the file size here
    for ($ii=0; $ii<$nooffiles; $ii++) {

    # $tt=index(@afarray[$ii],"tmp:/");
    $tt=index($afarray[$ii],"tmp:/");
    if ($tt eq -1){
    # $tempstr=$bcase_home_dir . "/" . @afarray[$ii];

    $tempstr=$bcase_home_dir . "/" . $afarray[$ii];
    }
    else{
    # $tempstr=@afarray[$ii];

    $tempstr=$afarray[$ii];
    $tempstr=~ s/://g;
    if ($tempstr ne ""){
    $tempstr="/". $tempstr;
    }
    }
    $tempstr=~ s/ /\\ /g;
    $scratch=0;
    $scratch=&bcase::get_file_size($tempstr);
    $attach_file_size= $attach_file_size+ $scratch;
    }
    $attach_file_size=$attach_file_size+$len;
    #&CgiError("FIle size so far " . $attach_file_size);
    if ($attach_file_size>$cgi_lib'maxdata) {
    &CgiDie("Request to receive too much data(more than
    $cgi_lib'maxdata bytes): $cgi_lib'maxdata-$attach_file_size bytes\n");
    }

    for ($ii=0; $ii<$nooffiles; $ii++) {
    # $tempstr= @afarray[$ii];

    $tempstr= $afarray[$ii];

    attach_file_wf($tempstr);
    #$tempstr=$tempstr . @afarray[$ii] . ",";
    }
    }

    The o/p to html page begins from here. There is no change to it:-

    &misc::functions_before($envlp, $cgi_data{'f'}, $cgi_data{'m'},
    $cgi_data{'s'}, "Message Sent");



    The function recently added:-
    sub attach_file_wf {
    my $f1 = $_[0];
    my $ctype;
    my $fname=$bcase_home_dir . "/" . $f1;
    my $tt;
    my @mypath = split(/\/|\\/, $f1);
    my $upfile1name = pop(@mypath);
    my $deletefile="";
    #check for the zip file
    $tt=index($f1,"tmp:/");
    if ($tt ne -1){ $deletefile="delete"; $fname="/tmp/" .
    $upfile1name}


    #my $upfile1name =$f1;
    if ($upfile1name) { }
    else { $upfile1name = 'anonymous'; }
    #if (open (TMPFILE, "< $cgi_sfn{$f1}")) {}
    #$string =~ s/regex/replacement/g;
    my $ff=$fname;
    $ff=~ s/ /\\ /g;
    #$upfile1name=~ s/ /\\ /g;
    #&CgiError("fname " . $ff);

    if (open (TMPFILE, "< $fname")) {
    #if (!defined($cgi_ct{$f1}) or $cgi_ct{$f1} eq "") {
    #$cgi_ct{$f1} = "application\/octet-stream";
    $ctype = &bcase::findmimetype($ff);
    #&CgiError(" ctype " . $ctype);
    if ($ctype eq ""){
    $ctype = "application\/octet-stream";
    }
    #}
    $cte = "BASE64";
    $decodeflag = "-b";
    if ($ctype =~ /^text\//i) {
    $cte = "quoted-printable"; $decodeflag = "-q";
    }
    seek(TMPFILE, 0 ,2);
    if (tell(TMPFILE) > 0) {
    close(TMPFILE);

    if (FAXMAIL) {
    $upfaxfile1name = $upfile1name;
    if (($upfile1name =~ /^iefaxing.sig$/i) or ($upfile1name =~
    /\.grp$/i)) {
    $upfaxfile1name .= ".ren";
    }
    print FAXMAIL <<_TO_END_;
    --$mkmailid
    Content-Type: $ctype; name=$upfaxfile1name
    Content-Transfer-Encoding: $cte

    _TO_END_
    }

    if (MAILALL) {
    print MAILALL <<_TO_END_;
    --$mkmailid
    Content-Type: $ctype; name=$upfile1name
    Content-Transfer-Encoding: $cte

    _TO_END_
    }

    if (MAIL) {
    print MAIL <<_TO_END_;
    --$mkmailid
    Content-Type: $ctype; name=$upfile1name
    Content-Transfer-Encoding: $cte

    _TO_END_
    }

    if (MAILME) {
    print MAILME <<_TO_END_;
    --$mkmailid
    Content-Type: $ctype; name=$upfile1name
    Content-Transfer-Encoding: $cte

    _TO_END_
    }


    if (FAXMAIL) { print FAXMAIL `$mimencoder $decodeflag $ff`
    or print FAXMAIL "ERROR:
    Can't open $mimencoder to encode the attachment : $!\n"; }
    if (MAILALL) { print MAILALL `$mimencoder $decodeflag $ff`
    or print MAILALL "ERROR:
    Can't open $mimencoder to encode the attachment : $!\n"; }
    if (MAIL) { print MAIL `$mimencoder $decodeflag $ff` or
    print MAIL "ERROR: Can't open $mimencoder to encode the attachment :
    $!\n"; }
    if (MAILME) { print MAILME `$mimencoder $decodeflag $ff` or
    print MAILME "ERROR: Can't open $mimencoder to encode the attachment :
    $!\n"; }
    #unlink ($cgi_sfn{$f1}) if (-e $cgi_sfn{$f1});
    if ($deletefile eq "delete"){
    unlink ($fname) if (-e $fname);
    }
    }
    else {
    close(TMPFILE);
    #unlink ($cgi_sfn{$f1}) if (-e $cgi_sfn{$f1});
    if ($deletefile eq "delete"){
    unlink ($fname) if (-e $fname);
    }
    }
    }
    }


    PLEASE HELPPPPPP.
     
    wizard, Sep 2, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Bonds
    Replies:
    2
    Views:
    2,774
    Amaryllis
    Aug 3, 2004
  2. VB Programmer

    Wierd error (web server not running 1.1)

    VB Programmer, Dec 17, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    2,941
    VB Programmer
    Dec 28, 2005
  3. Replies:
    5
    Views:
    80,412
    cpdarkman
    Aug 26, 2009
  4. BobbyOwens
    Replies:
    0
    Views:
    4,666
    BobbyOwens
    Jan 23, 2009
  5. Replies:
    0
    Views:
    777
Loading...

Share This Page