You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Roger Espel Llima <es...@iagora.net> on 2000/07/07 23:19:10 UTC

PerlSetupEnv is evil

In the process of optimizing a mod_perl setup (removing useless system
calls), I just spent a very boring couple hours trying to figure out
just why, when I gave Apache a request for a file that didn't exist, it
would first (as expected) stat() each path component, and then do it
again, skipping the *first* path component!

A slightly sanitized bit of strace output looked like this:

read(6, "GET /foo/bar/zoinx HTTP/1.0\r\n", 4096) = 40
read(6, "\r\n", 4096)                   = 2
stat("/www/html/foo/bar/zoinx", 0xbffff8ec) = -1 ENOENT
stat("/www/html/foo/bar", 0xbffff8ec) = -1 ENOENT
stat("/www/html/foo", 0xbffff8ec)    = -1 ENOENT
stat("/www/html", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/www/html/bar/zoinx", 0xbffff6bc) = -1 ENOENT
stat("/www/html/bar", 0xbffff6bc)    = -1 ENOENT
stat("/www/html", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0

Quite clearly, these 3 last stat() calls are wrong and should not be
there.

Poking around a bit more, it turned out that the TransHandlers were
being called twice for each such request; the second call would skip the
first part of the pathname.  i.e, if I gave Apache a "GET
/foo/bar/bletch" and the file didn't exist, it would first run the
TransHandler on "/foo/bar/bletch", then on "/bar/bletch".

It turns out that this is an indirect consequence of PerlSetupEnv; one
of the variables it tries to set is PATH_TRANSLATED, and in order to set
that, Apache runs a subrequest on the path_info (in this case, since
$DocumentRoot existed but $DocumentRoot/foo/ didn't, the path_info was
taken to be "/bar/bletch").

It also turns out that specifying "PerlSetupEnv Off" outside of any
<Directory> apparently gets ignored.  Is that a bug?  I put another
"PerlSetupEnv Off" in the <Directory> entry for the DocumentRoot, and
now it's not doing these annoying subrequests anymore.

Anyway, after tracing through this stuff, I'm more convinced than ever
that PerlSetupEnv is ugly and slow and to be avoided.

-- 
Roger Espel Llima, espel@iagora.net
http://www.iagora.com/~espel/index.html