You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Joel Reed <jr...@support.ddiworld.com> on 2000/03/27 16:09:09 UTC
Apache::ASP trouble passing objects from Application_OnStart
i'm getting segfaults passing an objection from global.asa to test.asp.
i have a global.asa like this...
#!/usr/bin/perl
use opal;
sub Application_OnStart {
my $pool = new o_connection_pool();
$Application->{pool} = $pool;
print "pool is $pool<br>";
print "app pool is " . $Application->{pool} . "<br>";
}
and i have test.asp like this...
<%@ LANGUAGE=PerlScript %>
<html><body>
<br>running test page...<br>
<hr>
<%
use opal;
my $pool = $Application->{pool};
$Response->Write("pool is $pool<br>");
$Response->Write("app pool is " . $Application->{pool} . "<br>");
#$pool->init("opal", "foo", "bar", 5);
%>
</body></html>
if i run this i get...
pool is o_connection_pool=HASH(0x849a11c) <<< FROM GLOBAL.ASA
app pool is o_connection_pool=HASH(0x8350854) <<< FROM GLOBAL.ASA
running test page... <<< FROM TEST.ASP
pool is o_connection_pool=HASH(0x862d71c) <<< FROM TEST.ASP
app pool is o_connection_pool=HASH(0x83e0700) <<< FROM TEST.ASP
and if i uncomment the $pool-init() call in test.asp the apache process totally
blows chunks (segfaults). shouldn't the HASH references above look the same
on global.asa and on test.asp ? i think i am segfaulting because the pool
object i create in global.asa doesn't make it cleanly over to test.asp.
when i run the all the code in test.asp everything works fine.
any suggestions? thanks for your help.
jr
--
------------------------------------------------------------------------
Joel W. Reed http://ruby.ddiworld.com/jreed
----------Everywhere is walking distance if you have the time.----------
Re: Apache::ASP trouble passing objects from Application_OnStart
Posted by Joshua Chamas <jo...@chamas.com>.
Joel Reed wrote:
>
> On Mar 27, joshua@chamas.com hacked the bitstream to say...
> Joshua>
> Joshua> I believe your opal code involves database connections,
> Joshua> which cannot be reused across processes. This is where
> Joshua> the apache process model gets you.
>
> just one additional note that may be helpful. i see the same
> weird (to me) output even when i do a
>
> /usr/sbin/httpd -X
>
> wouldn't that at least work?
>
No the process of serializing and unserializing data that
MLDBM does on data in and out of the SDBM_Files/DB_Files
will create a separate perl object each time, with the
objects data remaining the same.
-- Joshua
_________________________________________________________________
Joshua Chamas Chamas Enterprises Inc.
NodeWorks >> free web link monitoring Huntington Beach, CA USA
http://www.nodeworks.com 1-714-625-4051
Re: Apache::ASP trouble passing objects from Application_OnStart
Posted by Joel Reed <jr...@support.ddiworld.com>.
On Mar 27, joshua@chamas.com hacked the bitstream to say...
Joshua>
Joshua> I believe your opal code involves database connections,
Joshua> which cannot be reused across processes. This is where
Joshua> the apache process model gets you.
just one additional note that may be helpful. i see the same
weird (to me) output even when i do a
/usr/sbin/httpd -X
wouldn't that at least work?
jr
--
------------------------------------------------------------------------
Joel W. Reed http://ruby.ddiworld.com/jreed
-----------I've no idea what I'm doing out of bed. - Shadwell-----------
Re: Apache::ASP trouble passing objects from Application_OnStart
Posted by Joshua Chamas <jo...@chamas.com>.
Joel Reed wrote:
>
> EXECUTIVE SUMMARY:
>
> can i create ANY kind of object in Application_OnStart, store it in
> $Application->{foo} and get it out of an "foobar.asp" page? i see examples
> of storing things like "$Application->{foo} = 20" but no objects i guess?
>
Yes, you can store objects in $Application, but these
objects must not have any reliance on per process handles
and other inits that db connections often do.
> so this behavior (posted before) is correct?
>
> pool is o_connection_pool=HASH(0x863f3f0) << FROM GLOBAL.ASA
> app pool is o_connection_pool=HASH(0x863f3e4) << FROM GLOBAL.ASA
>
> running test page...
>
> pool is o_connection_pool=HASH(0x862d194) << FROM TEST.ASP
> app pool is o_connection_pool=HASH(0x862d20c) << FROM TEST.ASP
>
Yes this is correct... MLDBM will deserialize the data stored
in $Application into a new object with the same contents as before
but a different object in memory really.
> it would seem that each Apache process would process global.asa once
> and that subsequent ASP scripts on that process would then be able
> to get to the $Application->{} data created in Application_OnStart.
>
This is fine with raw data in general.
> is that a misconception? i did try your Script_OnStart suggestion
> but am still trying to figure out how to make a global-all-ASP files
> accessible var ( i guess i must use Exporter module discussed in
> mod_perl guide).
>
> this is what i tried, which gave same results...
>
> sub Script_OnStart {
> my $pool = new o_connection_pool();
> $Application->{pool} = $pool;
> print "pool is $pool<br>";
> print "app pool is " . $Application->{pool} . "<br>";
> }
>
Try (with PerlSetVar UseStrict 1):
use vars qw($Pool);
sub Script_OnStart {
$Pool = new o_connection_pool();
}
Then $Pool will be available in all your scripts, as your
scripts will run in the same package as Script_OnStart,
and $Pool is a global in that package.
-- Joshua
_________________________________________________________________
Joshua Chamas Chamas Enterprises Inc.
NodeWorks >> free web link monitoring Huntington Beach, CA USA
http://www.nodeworks.com 1-714-625-4051
Re: Apache::ASP trouble passing objects from Application_OnStart
Posted by Joel Reed <jr...@support.ddiworld.com>.
EXECUTIVE SUMMARY:
can i create ANY kind of object in Application_OnStart, store it in
$Application->{foo} and get it out of an "foobar.asp" page? i see examples
of storing things like "$Application->{foo} = 20" but no objects i guess?
Long form of question:
On Mar 27, joshua@chamas.com hacked the bitstream to say...
Joshua> I believe your opal code involves database connections,
Joshua> which cannot be reused across processes. This is where
Joshua> the apache process model gets you. You have to do per
Joshua> process db handle caching like Apache::DBI provides.
yes. could we assume EACH process will have a pool object for a sec?
(the reason why is when i write this code the pool will have
one connection per process under apache, but under NT/IIS
will have many connections as IIS is threaded ). also i don't
think i can use Apache::DBI because i'm doing db stuff thru
c++ objects & HODBC handles - although i'll review it.
Joshua> If you don't want to use Apache::DBI, then you can run
Joshua> your code for each script in Script_OnStart.
so this behavior (posted before) is correct?
pool is o_connection_pool=HASH(0x863f3f0) << FROM GLOBAL.ASA
app pool is o_connection_pool=HASH(0x863f3e4) << FROM GLOBAL.ASA
running test page...
pool is o_connection_pool=HASH(0x862d194) << FROM TEST.ASP
app pool is o_connection_pool=HASH(0x862d20c) << FROM TEST.ASP
it would seem that each Apache process would process global.asa once
and that subsequent ASP scripts on that process would then be able
to get to the $Application->{} data created in Application_OnStart.
is that a misconception? i did try your Script_OnStart suggestion
but am still trying to figure out how to make a global-all-ASP files
accessible var ( i guess i must use Exporter module discussed in
mod_perl guide).
this is what i tried, which gave same results...
sub Script_OnStart {
my $pool = new o_connection_pool();
$Application->{pool} = $pool;
print "pool is $pool<br>";
print "app pool is " . $Application->{pool} . "<br>";
}
thanks.
jr
--
------------------------------------------------------------------------
Joel W. Reed http://ruby.ddiworld.com/jreed
-----------I've no idea what I'm doing out of bed. - Shadwell-----------
Re: Apache::ASP trouble passing objects from Application_OnStart
Posted by Joshua Chamas <jo...@chamas.com>.
Joel Reed wrote:
>
> i'm getting segfaults passing an objection from global.asa to test.asp.
>
> i have a global.asa like this...
>
> #!/usr/bin/perl
>
> use opal;
>
> sub Application_OnStart {
> my $pool = new o_connection_pool();
> $Application->{pool} = $pool;
>
> print "pool is $pool<br>";
> print "app pool is " . $Application->{pool} . "<br>";
> }
>
> and i have test.asp like this...
>
I believe your opal code involves database connections,
which cannot be reused across processes. This is where
the apache process model gets you. You have to do per
process db handle caching like Apache::DBI provides.
If you don't want to use Apache::DBI, then you can run
your code for each script in Script_OnStart.
-- Joshua
_________________________________________________________________
Joshua Chamas Chamas Enterprises Inc.
NodeWorks >> free web link monitoring Huntington Beach, CA USA
http://www.nodeworks.com 1-714-625-4051