Cy Stanton wrote:
Hello all,
I am new to the list and joined in hopes that someone might be able to
help me with a problem I'm having with what seems to be a simple counter
script. In the interest of full disclosure, I must confess that I am
not really a programmer, but am trying to research this problem which my
ISP seems unable (so far) to figure out. Whatever info I can get I will
pass on to my ISP tech. I will try to provide as much info here as I
know:
On the pages of my web site, I have run a simple perl script intended to
place a counter on each page visited. The script worked great on my
previous ISP's web server, but now it is not working after I moved to a
new provider. I have made sure that the files are CHMODed to 755 and
even tried 777, including the directory. In my error log files, I get
the following error:
"Premature end of script headers"
Like I said, this counter script worked fine on my previous web sever.
The main difference seems to be that my previous provider used Perl
Version 5.004 (I think), but instead of using Perl Version X.XXXX, my
new provider used mod_perl 1.27 with Apache 1.3.2.7 (the use of
mod_perl is why I thought someone here might be able to help)

Besides badly written code, it has nothing to do with mod_perl. I bet if you configure it to run under mod_cgi you will have exactly the same problem. In fact you may be already running it under mod_cgi.


The fact that Apache prints "Premature end of script headers" tells you that the permissions are alright and it ivokes it as a script. Perhaps show us the relevant configuration bits from httpd.conf.

Do you have ScriptAlias entries in it? Do you have entries for mod_perl (which will have PerlHandler perl-script set and Alias may be). Also what the URL you invoke the script with?

It's also possible that you aren't running the script that you think you are running.

In any case, here is a bit cleaned up version of the script to give you proper error messages if something fails (it could use more work, but this forum is a wrong place to do that) and make the code a bit more readable.

#!/usr/bin/perl

use strict;
use warnings;

print "Content-type: text/html\n\n";

(my $PAGE = $ENV{'DOCUMENT_URI'}||'') =~ s|/|_|g;
exit 0 unless length $PAGE;
unless (-e $PAGE) {
    open NEW, ">$PAGE" or die "Can't open $PAGE: $!";
    print NEW "0";
    print 0;
    close NEW;
    exit 0;
}

open COUNTER, "+< $PAGE" or die "Can't open $PAGE: $!";
flock COUNTER, 2;
local $_ = <COUNTER>;
seek COUNTER, 0, 0;
$_++;
print;
print COUNTER;
close COUNTER;

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Reply via email to