CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Problem with Apache error.log entry

 



Bianca
User

Jun 4, 2010, 6:06 AM

Post #1 of 5 (1156 views)
Problem with Apache error.log entry Can't Post

Hi!

On Windows XP with Apache 2.2.8 and Strawberry Perl 5.10 the following script generates this line in error.log:

Code
[Thu Jun 03 13:42:06 2010] [error] [client 127.0.0.2] , referer: http://www.mylocaldomain.de/cgi-bin/script.pl


script.pl:

Code
#!/usr/bin/perl -W 
use strict;
use warnings;
use IO::Handle; STDOUT -> autoflush (1);
use CGI;
my $zeit = time;
print CGI -> new -> header . <<HTML_TEIL;
<html>
<head>
</head>
<body>
<p>Bin da um $zeit mit PID $$</p>
</body>
</html>
HTML_TEIL
close STDOUT;

open (my $fh,">test.parent.$$" . ".txt");
print $fh "test";
close $fh;

It work's fine, no problems. But only a comma in error.log?
And on Linux with Apache there's no entry in error.log by this script.
Any ideas, why Apache generates this error?
Thanks


FishMonger
Veteran / Moderator

Jun 4, 2010, 8:58 AM

Post #2 of 5 (1152 views)
Re: [Bianca] Problem with Apache error.log entry [In reply to] Can't Post

There's no reason to use both the -W switch and the warnings pragma. The pragma is the preferred choice.


Quote

Code
use IO::Handle; STDOUT -> autoflush (1);


Don't put multiple statements on a single line.
Why are you using that module to only set autoflush, when it would be simpler to just set $| to a true value? i.e.,

Code
$|++;



Quote

Code
print CGI -> new -> header . <<HTML_TEIL;  
<html>
<head>
</head>
<body>
<p>Bin da um $zeit mit PID $$</p>
</body>
</html>
HTML_TEIL


That's a poor approach.

Better written as:

Code
my $cgi = CGI->new; 

print $cgi->header,
$cgi->start_html("page title"),
$cgi->p("Bin da um $zeit mit PID $$"),
$cgi->end_html;



Quote

Code
open (my $fh,">test.parent.$$" . ".txt");


It's better to use the 3 arg form of open and you should ALWAYS check the return code of an open call to verify that it was successful and take action if it wasn't.


Code
my $testfile = "test.parent.$$" . '.txt'; 
open my $fh, '>', $testfile or die "failed to open '$testfile' $!";



Bianca
User

Jun 4, 2010, 10:12 AM

Post #3 of 5 (1147 views)
Re: [FishMonger] Problem with Apache error.log entry [In reply to] Can't Post

Hi FischMonger,
thanks for your help.
But it changes nothing:


Code
#!/usr/bin/perl 
use strict;
#use warnings;
use CGI;
$| ++;
my $zeit = time;
my $cgi = CGI->new;
print $cgi->header,
$cgi->start_html("page title"),
$cgi->p("Bin da um $zeit mit PID $$"),
$cgi->end_html;

close STDOUT;
my $testfile = "test.parent.$$" . '.txt';
open my $fh, '>', $testfile or die "failed to open '$testfile' $!";


error.log:

Code
[Fri Jun 04 19:10:03 2010] [error] [client 127.0.0.2]



FishMonger
Veteran / Moderator

Jun 4, 2010, 10:42 AM

Post #4 of 5 (1143 views)
Re: [Bianca] Problem with Apache error.log entry [In reply to] Can't Post

1) Don't close STDOUT

2) Redirect STDERR to the browser via CGI::Carp

3) Move the open call above the html output

Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);

$| ++;
my $zeit = time;
my $cgi = CGI->new;
my $testfile = "test.parent.$$" . '.txt';

print $cgi->header;
warningsToBrowser(1); # warnings show up as html comments

# I haven't tested it, but I suspect the open call is failing
open my $fh, '>', $testfile or die "failed to open '$testfile' $!";
print $fh 'test';
close $fh or die "failed to close $testfile $!";

print $cgi->start_html("page title"),
$cgi->p("Bin da um $zeit mit PID $$"),
$cgi->end_html;

exit;



Bianca
User

Jun 5, 2010, 9:42 PM

Post #5 of 5 (1112 views)
Re: [FishMonger] Problem with Apache error.log entry [In reply to] Can't Post

I have to explain the problem.
This example script is a small part of a bigger one to show the structure and provoke the error.
The big script works on Linux/Apache/Perl 5.8.5 and does something in file system. It works longer than apache's CGI timeout.
Because of this I close STDOUT at this position. In the big script I request via Ajax every second if script is ready.
If I don't close STDOUT I get "Internal Server Error".
So this is the solution for the Linux/Apache Server. On Linux/Apache works very fine and there are no error.log entries.

But if I run the same big script on WindowsXP/Apache/Strawberry 5.10.1 it produces the "comma" error.log line

Code
[Thu Jun 03 13:42:06 2010] [error] [client 127.0.0.2] , referer: http://www.mylocaldomain.de/cgi-bin/script.pl"

.
Also on Windows it works very fine but this error.log entry disturb.
And for that I write this small sample script and it produces this empty error.log line

Code
[Fri Jun 04 19:10:03 2010] [error] [client 127.0.0.2]


And now my question is, why produces the scripts only on Windows/Apache/Strawberry this strange error.log line with no content/message? For which is this line? What will tell me apache with this line?

By the way: If I uncomment the line close STDOUT in the small sample script, there is no error line in error.log. But that doesn't help Crazy
Thank you very much and sorry for bad english.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives