You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Stephen Bardsley <sb...@rlwinc.com> on 2001/06/15 18:07:04 UTC

intermittent failure reading a file

Greetings,

There is probably a ridiculously simple reason for this, but...

Using Apache::ASP I have a script that reads the contents of
a file, line by line in a loop.  The file always has data, but
sometimes the loop terminates as if the EOF has been reached.
There must be a caching issue that I'm missing, but I don't know
where to look.  Any suggests are appreciated.

Steve
_____________________
Stephen Bardsley
RLW Inc.
Malta, NY

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: intermittent failure reading a file

Posted by ivan <iv...@420.am>.
On Fri, Jun 15, 2001 at 12:14:39PM -0700, Joshua Chamas wrote:
> Stephen Bardsley wrote:
> > 
> > my $wfname = 'a session based filename';
> > my $csv = Text::CSV->new();
> > my @fft = ();
> > my @line = ();
> > 
> > open(IN, "./fft <$wfname |") or die "could not open $wfname";
> > while (<IN>) {
> >   $csv->parse($_);
> >   @line = $csv->fields();
> >   push(@fft, $line[0]);
> > }
> > close(IN);
> > 
> 
> I don't know that while(<IN>) is a good idea,

It's a standard Perl construct and it works fine.

> I wonder what would happen if somehow a line
> was blank, would that be boolean 0 ?

Nope.  "Blank" lines contain a single \n, so they evaluate as true.
while (<FILEHANDLE>) is a pretty common perl construct.

>  Try 
> instead:  for(<IN>), or even
> 
>  my @lines = <IN>
>  for ( @lines ) {
> 
> -- Josh
> 
> _________________________________________________________________
> Joshua Chamas                           Chamas Enterprises Inc.
> NodeWorks <- Web Link Checking          Huntington Beach, CA  USA 
> http://www.nodeworks.com                1-714-625-4051
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
> For additional commands, e-mail: asp-help@perl.apache.org
> 

-- 
meow
_ivan

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: intermittent failure reading a file

Posted by Thanos Chatziathanassiou <tc...@arx.gr>.
> > > grep '$/.\=' ASP.pm
> >             local $/ = undef;
> >     local $/ = undef;
> > If this problem persists for you.  I would carefully
> > look at the data that you have read in so far
> > while debugging, to see where it stops in the file.
> > Also, if all else fails, you might try sysread(IN)
> > and then @lines = split(/\n/, $data)

Wouldn't this force the httpd serving the request to grow so large as to
sulrp in the whole file ?
Whatever an httpd child takes in memory, it does not give away, so 50
children serving this request would consume
50*(normal_mod_perl_httpd_size+file_size)
This could easily lead to memory shortage, if the file is large.
(I should know, I've had that problem already).

Thanos Chatziathanassiou



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Stephen Bardsley <sb...@rlwinc.com>.
Josh:

The sysread() call works reliably!
Thanks for the good call.

Regards,
Steve
_____________________
Stephen Bardsley
RLW Inc.
Malta, NY 

> -----Original Message-----
> From: Joshua Chamas [mailto:joshua@chamas.com]
> Sent: Friday, June 15, 2001 3:35 PM
> To: Stephen Bardsley
> Cc: asp@perl.apache.org
> Subject: Re: intermittent failure reading a file
> 
> 
> Stephen Bardsley wrote:
> > 
> > Josh:
> > 
> > The problem only occurs under Apache::ASP,
> > but works wonderfully in a pure perl environment.
> > 
> > Steve
> > 
> 
> I don't think Apache::ASP is getting in your way,
> but something else in the mod_perl env might be.  In 
> particular, if $/ were ever set to anything else,
> that would affect the behavior of <IN>
> 
> > grep '$/.\=' ASP.pm
>             local $/ = undef;
>     local $/ = undef;
> 
> so its not Apache::ASP
> 
> If this problem persists for you.  I would carefully
> look at the data that you have read in so far
> while debugging, to see where it stops in the file.
> Also, if all else fails, you might try sysread(IN)
> and then @lines = split(/\n/, $data)
> 
> --Josh
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
> For additional commands, e-mail: asp-help@perl.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: intermittent failure reading a file

Posted by Joshua Chamas <jo...@chamas.com>.
Stephen Bardsley wrote:
> 
> Josh:
> 
> The problem only occurs under Apache::ASP,
> but works wonderfully in a pure perl environment.
> 
> Steve
> 

I don't think Apache::ASP is getting in your way,
but something else in the mod_perl env might be.  In 
particular, if $/ were ever set to anything else,
that would affect the behavior of <IN>

> grep '$/.\=' ASP.pm
            local $/ = undef;
    local $/ = undef;

so its not Apache::ASP

If this problem persists for you.  I would carefully
look at the data that you have read in so far
while debugging, to see where it stops in the file.
Also, if all else fails, you might try sysread(IN)
and then @lines = split(/\n/, $data)

--Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Stephen Bardsley <sb...@rlwinc.com>.
Josh:

The problem only occurs under Apache::ASP,
but works wonderfully in a pure perl environment.

Steve


-----Original Message-----
From: Joshua Chamas [mailto:joshua@chamas.com]
Sent: Friday, June 15, 2001 3:15 PM
To: Stephen Bardsley
Cc: asp@perl.apache.org
Subject: Re: intermittent failure reading a file


Stephen Bardsley wrote:
> 
> my $wfname = 'a session based filename';
> my $csv = Text::CSV->new();
> my @fft = ();
> my @line = ();
> 
> open(IN, "./fft <$wfname |") or die "could not open $wfname";
> while (<IN>) {
>   $csv->parse($_);
>   @line = $csv->fields();
>   push(@fft, $line[0]);
> }
> close(IN);
> 

I don't know that while(<IN>) is a good idea,
I wonder what would happen if somehow a line
was blank, would that be boolean 0 ?  Try 
instead:  for(<IN>), or even

 my @lines = <IN>
 for ( @lines ) {

-- Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks <- Web Link Checking          Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: intermittent failure reading a file

Posted by Dariusz Pietrzak <da...@ajax.umcs.lublin.pl>.
> I don't know that while(<IN>) is a good idea,
> I wonder what would happen if somehow a line
> was blank, would that be boolean 0 ?  Try 
hmm, shouldn't be, never happened to me.

>  my @lines = <IN>
>  for ( @lines ) {
nice and fast, yup, I vote for this.


--
Dariusz Pietrzak
Certified Nobody


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Stephen Bardsley <sb...@rlwinc.com>.
Josh:

I tried your suggestion, but the problem persists.

Steve

-----Original Message-----
From: Joshua Chamas [mailto:joshua@chamas.com]
Sent: Friday, June 15, 2001 3:15 PM
To: Stephen Bardsley
Cc: asp@perl.apache.org
Subject: Re: intermittent failure reading a file

I don't know that while(<IN>) is a good idea,
I wonder what would happen if somehow a line
was blank, would that be boolean 0 ?  Try 
instead:  for(<IN>), or even

 my @lines = <IN>
 for ( @lines ) {

-- Josh


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: intermittent failure reading a file

Posted by Joshua Chamas <jo...@chamas.com>.
Stephen Bardsley wrote:
> 
> my $wfname = 'a session based filename';
> my $csv = Text::CSV->new();
> my @fft = ();
> my @line = ();
> 
> open(IN, "./fft <$wfname |") or die "could not open $wfname";
> while (<IN>) {
>   $csv->parse($_);
>   @line = $csv->fields();
>   push(@fft, $line[0]);
> }
> close(IN);
> 

I don't know that while(<IN>) is a good idea,
I wonder what would happen if somehow a line
was blank, would that be boolean 0 ?  Try 
instead:  for(<IN>), or even

 my @lines = <IN>
 for ( @lines ) {

-- Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks <- Web Link Checking          Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Stephen Bardsley <sb...@rlwinc.com>.
Good point.  I looked into that and I have of plenty of
processes available.  No indication of resource limitations
in any logs etc.

Steve

> -----Original Message-----
> From: Dariusz Pietrzak [mailto:dariush@ajax.umcs.lublin.pl]
> Sent: Friday, June 15, 2001 3:26 PM
> To: Stephen Bardsley
> Cc: asp@perl.apache.org
> Subject: RE: intermittent failure reading a file
> 
> 
> > > open(IN, "./fft <$wfname |") or die "could not open $wfname";
> anyhow, what does fft do?
> Suppose there are limits of processes run by www-data/httpd user
> you can run out of them. 
> 
> --
> Dariusz Pietrzak
> Certified Nobody
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Dariusz Pietrzak <da...@ajax.umcs.lublin.pl>.
> > open(IN, "./fft <$wfname |") or die "could not open $wfname";
anyhow, what does fft do?
Suppose there are limits of processes run by www-data/httpd user
you can run out of them. 

--
Dariusz Pietrzak
Certified Nobody


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Stephen Bardsley <sb...@rlwinc.com>.
I've tried both relative and absolute pathnames.  No difference.
I always prefer relative unless there is a compelling reason to
do otherwise. Thoughts?

Steve

-----Original Message-----
From: Dariusz Pietrzak [mailto:dariush@ajax.umcs.lublin.pl]
Sent: Friday, June 15, 2001 3:16 PM
To: Stephen Bardsley
Cc: asp@perl.apache.org
Subject: RE: intermittent failure reading a file



> open(IN, "./fft <$wfname |") or die "could not open $wfname";
What is THAT?!
 where is path to fft?




---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Dariusz Pietrzak <da...@ajax.umcs.lublin.pl>.
> open(IN, "./fft <$wfname |") or die "could not open $wfname";
What is THAT?!
 where is path to fft?



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: intermittent failure reading a file

Posted by Stephen Bardsley <sb...@rlwinc.com>.
Joshua Chamas wrote:
>
>What your code look like?
>
>--Josh


Josh:

This is a fragment of a large script, but I have isolated
the problem to it:

<--- start of fragment ----->
(use Text::CSV; is somewhere above)

my $wfname = 'a session based filename';
my $csv = Text::CSV->new();
my @fft = ();
my @line = ();

open(IN, "./fft <$wfname |") or die "could not open $wfname";
while (<IN>) {
  $csv->parse($_);
  @line = $csv->fields();
  push(@fft, $line[0]);
}
close(IN);

$csv = ();

<--- end of fragment ----->

The indications are that the @fft variable will be in one of
three states when the loop terminates:
   1.  correct (my personal favorite)
   2.  have 2 empty elements (never correct)
   3.  undefined (real bad)

It seems that state 1 occurs about 30% of the time, but that
might just be a consequence of my Apache configuration (i.e. the
number of processes I allow, etc.).

Regards,
Steve



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: intermittent failure reading a file

Posted by Joshua Chamas <jo...@chamas.com>.
Stephen Bardsley wrote:
> 
> Greetings,
> 
> There is probably a ridiculously simple reason for this, but...
> 
> Using Apache::ASP I have a script that reads the contents of
> a file, line by line in a loop.  The file always has data, but
> sometimes the loop terminates as if the EOF has been reached.
> There must be a caching issue that I'm missing, but I don't know
> where to look.  Any suggests are appreciated.
> 

What your code look like?

--Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org