You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Josh Bernstein <jo...@engr.arizona.edu> on 2002/07/12 01:56:38 UTC
Working Directory
After just upgrading to mod_perl2 with Apache2. My current @INC path
includes a "." on the end, which should reference the current working
directory, and therefore correctly locate include locate in the script's
working directory. The problem is that the Working Directory is set to
"/". My question is how can I set the working directory to be the
location of where the script is running..... (This would make mod_perl
correctly locate file that I have included in the running script ie:
require "./file.pl") Can this be done from within Apache?
I've tried variations of PerlSetEnv but I can't seem to get it to
work. I've even read the mod_perl2 user's guide. Thanks for your help..
-Joshua Bernstein
Systems Administrator
College of Engineering
University of Arizona
Tucson, Arizona, USA
Re: Working Directory
Posted by Stas Bekman <st...@stason.org>.
Josh Bernstein wrote:
> Sounds great? Does he have anything that I could play with? I'm really
> dying for that chdir(), my programmer says he depends on that
> functionality. I'd even volunteer to do some benchmarks and what not
> associated with the extra overhead of making the function thread safe.
He should probably announce it soon, when he returns from vacation. why
don't you test with prefork for now? and Apache::compat +
Apache::Registry from 1.x?
> If its not really yet, what do you feel is currently the best work
> around? I've read through the archives and I'm just try to figure which
> one to use...
there are no workarounds to having a thread-safe cwd, other than using
full paths.
> -Josh
>
>
> Stas Bekman wrote:
>
>> Elizabeth Mattijsen wrote:
>>
>>> At 06:10 PM 7/16/02 +0000, Stas Bekman wrote:
>>>
>>>>> Arthur told me he either had, or was going to fix this (on IRC).
>>>>
>>>>
>>>>
>>>> Yup, Arthur is working on an external package
>>>> (ex::threads::safecwd?) which should solve this problem. Viva
>>>> Arthur! I'll keep you updated once it gets released.
>>>
>>>
>>>
>>>
>>> Check out Arthur's article on Perl.com:
>>>
>>> http://www.perl.com/pub/a/2002/06/11/threads.html
>>
>>
>>
>> I read the article ;) The article doesn't say that there is going to
>> be a module that will do all this work for you. I just wanted to share
>> the happy news that such a module is about to emerge.
>>
>> Most of the people don't care how things are implemented, they just
>> want to know that the API they use is thread-safe, which is how it
>> should be with chdir() and friends.
>>
>> Though you realize that that this wrapper will incur a certain
>> overhead, which needs to be benchmarked. And if that overhead is of
>> any significant value, we should provide a switch to turn if off for
>> those who don't rely on chdir() and therefore can get a better
>> performance. I'm talking mainly about the Registry family in this
>> case, but I can see that this functionality could be provided on the
>> mod_perl core level (PerlSafeCwd flag?).
>>
>> __________________________________________________________________
>> 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
>>
>>
>
>
--
__________________________________________________________________
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
Re: Working Directory
Posted by Josh Bernstein <jo...@engr.arizona.edu>.
Sounds great? Does he have anything that I could play with? I'm really
dying for that chdir(), my programmer says he depends on that
functionality. I'd even volunteer to do some benchmarks and what not
associated with the extra overhead of making the function thread safe.
If its not really yet, what do you feel is currently the best work
around? I've read through the archives and I'm just try to figure which
one to use...
-Josh
Stas Bekman wrote:
> Elizabeth Mattijsen wrote:
>
>> At 06:10 PM 7/16/02 +0000, Stas Bekman wrote:
>>
>>>> Arthur told me he either had, or was going to fix this (on IRC).
>>>
>>>
>>> Yup, Arthur is working on an external package
>>> (ex::threads::safecwd?) which should solve this problem. Viva
>>> Arthur! I'll keep you updated once it gets released.
>>
>>
>>
>> Check out Arthur's article on Perl.com:
>>
>> http://www.perl.com/pub/a/2002/06/11/threads.html
>
>
> I read the article ;) The article doesn't say that there is going to
> be a module that will do all this work for you. I just wanted to share
> the happy news that such a module is about to emerge.
>
> Most of the people don't care how things are implemented, they just
> want to know that the API they use is thread-safe, which is how it
> should be with chdir() and friends.
>
> Though you realize that that this wrapper will incur a certain
> overhead, which needs to be benchmarked. And if that overhead is of
> any significant value, we should provide a switch to turn if off for
> those who don't rely on chdir() and therefore can get a better
> performance. I'm talking mainly about the Registry family in this
> case, but I can see that this functionality could be provided on the
> mod_perl core level (PerlSafeCwd flag?).
>
> __________________________________________________________________
> 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
>
>
Re: Working Directory
Posted by Stas Bekman <st...@stason.org>.
Elizabeth Mattijsen wrote:
> At 06:10 PM 7/16/02 +0000, Stas Bekman wrote:
>
>>> Arthur told me he either had, or was going to fix this (on IRC).
>>
>> Yup, Arthur is working on an external package (ex::threads::safecwd?)
>> which should solve this problem. Viva Arthur! I'll keep you updated
>> once it gets released.
>
>
> Check out Arthur's article on Perl.com:
>
> http://www.perl.com/pub/a/2002/06/11/threads.html
I read the article ;) The article doesn't say that there is going to be
a module that will do all this work for you. I just wanted to share the
happy news that such a module is about to emerge.
Most of the people don't care how things are implemented, they just want
to know that the API they use is thread-safe, which is how it should be
with chdir() and friends.
Though you realize that that this wrapper will incur a certain overhead,
which needs to be benchmarked. And if that overhead is of any
significant value, we should provide a switch to turn if off for those
who don't rely on chdir() and therefore can get a better performance.
I'm talking mainly about the Registry family in this case, but I can see
that this functionality could be provided on the mod_perl core level
(PerlSafeCwd flag?).
__________________________________________________________________
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
Re: Working Directory
Posted by Elizabeth Mattijsen <li...@dijkmat.nl>.
At 06:10 PM 7/16/02 +0000, Stas Bekman wrote:
>>Arthur told me he either had, or was going to fix this (on IRC).
>Yup, Arthur is working on an external package (ex::threads::safecwd?)
>which should solve this problem. Viva Arthur! I'll keep you updated once
>it gets released.
Check out Arthur's article on Perl.com:
http://www.perl.com/pub/a/2002/06/11/threads.html
Liz
Re: Working Directory
Posted by Stas Bekman <st...@stason.org>.
Matt Sergeant wrote:
> On Fri, 12 Jul 2002, Stas Bekman wrote:
>
>
>>Josh Bernstein wrote:
>>
>>> After just upgrading to mod_perl2 with Apache2. My current @INC path
>>>includes a "." on the end, which should reference the current working
>>>directory, and therefore correctly locate include locate in the script's
>>>working directory. The problem is that the Working Directory is set to
>>>"/". My question is how can I set the working directory to be the
>>>location of where the script is running..... (This would make mod_perl
>>>correctly locate file that I have included in the running script ie:
>>>require "./file.pl") Can this be done from within Apache?
>>>
>>> I've tried variations of PerlSetEnv but I can't seem to get it to
>>>work. I've even read the mod_perl2 user's guide. Thanks for your help..
>>
>>chdir is not a thread-safe function, (there is only one CWD per
>>application) therefore the new ModPerl::Registry doesn't chdir to the
>>dir of the script. We have discussed various workarounds on the dev
>>list, but none of them has been applied yet.
>>http://mathforum.org/discussions/epi-search/modperl-dev.html
>>(search for 'chdir thread')
>
>
> Arthur told me he either had, or was going to fix this (on IRC).
Yup, Arthur is working on an external package (ex::threads::safecwd?)
which should solve this problem. Viva Arthur! I'll keep you updated once
it gets released.
__________________________________________________________________
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
Re: Working Directory
Posted by Matt Sergeant <ma...@sergeant.org>.
On Fri, 12 Jul 2002, Stas Bekman wrote:
> Josh Bernstein wrote:
> > After just upgrading to mod_perl2 with Apache2. My current @INC path
> > includes a "." on the end, which should reference the current working
> > directory, and therefore correctly locate include locate in the script's
> > working directory. The problem is that the Working Directory is set to
> > "/". My question is how can I set the working directory to be the
> > location of where the script is running..... (This would make mod_perl
> > correctly locate file that I have included in the running script ie:
> > require "./file.pl") Can this be done from within Apache?
> >
> > I've tried variations of PerlSetEnv but I can't seem to get it to
> > work. I've even read the mod_perl2 user's guide. Thanks for your help..
>
> chdir is not a thread-safe function, (there is only one CWD per
> application) therefore the new ModPerl::Registry doesn't chdir to the
> dir of the script. We have discussed various workarounds on the dev
> list, but none of them has been applied yet.
> http://mathforum.org/discussions/epi-search/modperl-dev.html
> (search for 'chdir thread')
Arthur told me he either had, or was going to fix this (on IRC).
--
<!-- Matt -->
<:->Get a smart net</:->
Re: Working Directory
Posted by Stas Bekman <st...@stason.org>.
Josh Bernstein wrote:
> After just upgrading to mod_perl2 with Apache2. My current @INC path
> includes a "." on the end, which should reference the current working
> directory, and therefore correctly locate include locate in the script's
> working directory. The problem is that the Working Directory is set to
> "/". My question is how can I set the working directory to be the
> location of where the script is running..... (This would make mod_perl
> correctly locate file that I have included in the running script ie:
> require "./file.pl") Can this be done from within Apache?
>
> I've tried variations of PerlSetEnv but I can't seem to get it to
> work. I've even read the mod_perl2 user's guide. Thanks for your help..
chdir is not a thread-safe function, (there is only one CWD per
application) therefore the new ModPerl::Registry doesn't chdir to the
dir of the script. We have discussed various workarounds on the dev
list, but none of them has been applied yet.
http://mathforum.org/discussions/epi-search/modperl-dev.html
(search for 'chdir thread')
If you want to extend @INC to include some extra paths change it during
the startup.
It's possible that we will have a special version of registry
(ModPerl::RegistrySafeChdir) which does the right thing but you pay the
price of a worse performance, read more about it here:
http://www.perl.com/lpt/a/2002/06/11/threads.html
It's also possible that there will be ModPerl::RegistryNonThreaded or
something like that, which will chdir just like the registry in mod_perl
1.0 did, which will restrict your code to run only on the prefork mpm.
The idea that the main ModPerl::Registry should work identically across
different mpms.
__________________________________________________________________
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
Re: Working Directory
Posted by Stas Bekman <st...@stason.org>.
Francesc X.Noria wrote:
> On Thu, 11 Jul 2002 16:56:38 -0700
> Josh Bernstein <jo...@engr.arizona.edu> wrote:
>
> : "/". My question is how can I set the working directory to be the
> : location of where the script is running..... (This would make mod_perl
> : correctly locate file that I have included in the running script ie:
> : require "./file.pl") Can this be done from within Apache?
>
> Maybe you could use this trick:
>
> use FindBin qw($Bin);
> use lib $Bin;
You cannot. FindBin does its magic in the BEGIN block, which will run
only once under mod_perl.
http://perl.apache.org/release/docs/1.0/guide/snippets.html#More_on_Relative_Paths
you can do 'do FindBin', but you add the overhead.
__________________________________________________________________
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
Re: Working Directory
Posted by "Francesc X. Noria" <fx...@isoco.com>.
On Thu, 11 Jul 2002 16:56:38 -0700
Josh Bernstein <jo...@engr.arizona.edu> wrote:
: "/". My question is how can I set the working directory to be the
: location of where the script is running..... (This would make mod_perl
: correctly locate file that I have included in the running script ie:
: require "./file.pl") Can this be done from within Apache?
Maybe you could use this trick:
use FindBin qw($Bin);
use lib $Bin;
Take a look at the standard idioms to modify @INC under mod_perl as
well, they are explained here:
http://perl.apache.org/guide/porting.html#_INC_and_mod_perl
-- fxn