You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dodger <se...@aquest.com> on 2004/04/16 19:37:37 UTC

Autoflush without NPH...

Hi, all.

Okay here's one I'm curious about... don't need it immediately, I think, but
it would be nice to undesatand ahead of time.

According to the mod_perl documentation, it says:

-----

To run a Non Parsed Header CGI script under mod_perl, simply add to your
code:

  local $| = 1;

And if you normally set PerlSendHeader On, add this to your server's
configuration file:

  <Files */nph-*>
    PerlSendHeader Off
  </Files>

-----

Now, as long as PerlSendHeader is*On* will that make sure that it does NOT
run as an NPH script if $! is set to 1?

The reason is that I have been known to set $| to 1 when I've got a
*regular* script doing thngs that might go slowly (such as, for instance but
not vital at the moment, on a 'Join' page printing out some reassurance to
the user that things are being processed while connecting to the SMTP server
to send the validation mail, which can be slow).

I've even had some comments that it looks really neat when I do this, since
a newline doesn't mean a newline in HTML so I can do things like:

Doing something that's slow: Done
Doing something even slower: . . . Done

(Even if the HTML source output ends up ugly)
(The 'Done' parts and the dots appear after things are done or stages of the
things are done, and show up on the browser as they are complete, as the
page simply hasn't finished loading, but it looks all dynamically
interactive when it's  really not, plus there's no 'wait time' where the
user might be hitting refresh and stupid things like that).

However, if the PerlSendHeader On doesn't stop it completely from being an
NPH script, then doing this would theoretically cause problems, I'd think.

Any elucidation out there?

-- 
Dodger


-- 
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


Re: Autoflush without NPH...

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, 2004-04-16 at 14:25, Dodger wrote:
> All I have to go on is the documentation, which is noticably sparse in this
> area

You're welcome to improve it.  NPH is not really a standard, just a
common practice, and it's mostly irrelevant for mod_perl since you have
complete control over your output, including headers.  It's just a
mod_cgi compatibility thing.

>  -- and DID indicate that turning autoflush on is really part of it.

Turning on autoflush is something you do with perl to prevent it from
buffering things.  NPH is a server behavior from mod_cgi, so it can't
really include anything perl-specific.  Again, setting autoflush is just
a common practice when writing NPH scripts in perl because of the way
they are usually used.

> I got the impression that Apache::Registry does stuff when dealing
> with the script before running it, and I thought that it might
> possibly be doing some magic behind the scenes if it located $| being
> turned on.

Nothing that I can recall.  If you're curious about what
Apache::Registry does, you can always look at the code.  It's short, all
in perl, and pretty easy to follow.

> Anyway, I just tried it and it didn't seem to pay any attention to the value
> of $|. Seemed to block buffer everything anyway.

Turning on autoflush is enough to prevent perl/mod_perl from buffering. 
There is probably something else going on.

- Perrin


-- 
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


Re: Autoflush without NPH...

Posted by Dodger <se...@aquest.com>.
----- Original Message ----- 
From: "Perrin Harkins" <pe...@elem.com>
To: "Dodger" <se...@aquest.com>
Cc: "Modperl List" <mo...@perl.apache.org>
Sent: Friday, April 16, 2004 10:52 AM
Subject: Re: Autoflush without NPH...


> On Fri, 2004-04-16 at 13:37, Dodger wrote:
> > Now, as long as PerlSendHeader is*On* will that make sure that it does
NOT
> > run as an NPH script if $! is set to 1?
>
> Do you understand what an NPH script is?  It simply means that the
> server is not parsing your output and adding headers, the way it
> normally does when running under mod_cgi.  Technically, all mod_perl
> handlers and any Apache::Registry script run with PerlSendHeader off is
> equivalent to an NPH script.

Yep, of course. I've written several. At least half I've written won't work
on IE because it won't do replace boundaries correctly. One was a nifty
web-based MUD client, without so much as a hint of java or anything like
that.

> Turning autoflush on is not really part of it, but since people usually
> are turning off header parsing in order to output something that
> updates, it is a common practice.  Buffering would kill things like
> server-push, which was the main thing NPH scripts were used for.
>
> - Perrin

All I have to go on is the documentation, which is noticably sparse in this
area -- and DID indicate that turning autoflush on is really part of it. I
got the impression that Apache::Registry does stuff when dealing with the
script before running it, and I thought that it might possibly be doing some
magic behind the scenes if it located $| being turned on.

Anyway, I just tried it and it didn't seemto pay any attention to the vaue
of $|. Seemed to block buffer everything anyway.

-- 
Dodger


-- 
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


Re: Autoflush without NPH...

Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
[...]

> Technically, all mod_perl
> handlers and any Apache::Registry script run with PerlSendHeader off is
> equivalent to an NPH script.

BTW, that's true only for Apache 1.3. Apache 2.0 will force its own headers 
sending unless you set $r->assbackwards(1);, which is done automatically in 
registry handlers if the script name starts with nph-

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org 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


Re: Autoflush without NPH...

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, 2004-04-16 at 13:37, Dodger wrote:
> Now, as long as PerlSendHeader is*On* will that make sure that it does NOT
> run as an NPH script if $! is set to 1?

Do you understand what an NPH script is?  It simply means that the
server is not parsing your output and adding headers, the way it
normally does when running under mod_cgi.  Technically, all mod_perl
handlers and any Apache::Registry script run with PerlSendHeader off is
equivalent to an NPH script.

Turning autoflush on is not really part of it, but since people usually
are turning off header parsing in order to output something that
updates, it is a common practice.  Buffering would kill things like
server-push, which was the main thing NPH scripts were used for.

- Perrin


-- 
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