Re: Persistent Net::Telnet Objects in Apache2/mod_perl2

2002-07-15 Thread Stas Bekman

French, Shawn wrote:
> Stas Bekman wrote:
> 
>>It seems that you are after the same functionality as Apache::DBI, you 
>>want a pool of items that you want to be able to choose from. 
>>Look for threads::shared (perl 5.8.0), just create a shared hash with 
>>keys that you use for the map and the values for the actual connection
> 
> objects.
> 
> YES!!! That is exactly what I need! Where do I find perl 5.8.0 and
> threads::shared? I need a perl binary for windows since I'm without a
> compiler...

Wait about one more week and it's going to be released. e.g. see 
http://use.perl.org/

> As for the apache notes, I hope your right that it would be easy to
> implement, otherwise I can't upgrade to apache2 without some _huge_
> workarounds... which are always nice to avoid :)

Apache 2.0 wasn't released yet in any case.

__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com




RE: Persistent Net::Telnet Objects in Apache2/mod_perl2

2002-07-15 Thread French, Shawn


Stas Bekman wrote:
> It seems that you are after the same functionality as Apache::DBI, you 
> want a pool of items that you want to be able to choose from. 
> Look for threads::shared (perl 5.8.0), just create a shared hash with 
> keys that you use for the map and the values for the actual connection
objects.

YES!!! That is exactly what I need! Where do I find perl 5.8.0 and
threads::shared? I need a perl binary for windows since I'm without a
compiler...

As for the apache notes, I hope your right that it would be easy to
implement, otherwise I can't upgrade to apache2 without some _huge_
workarounds... which are always nice to avoid :)

Shawn



Re: Persistent Net::Telnet Objects in Apache2/mod_perl2

2002-07-15 Thread Stas Bekman

French, Shawn wrote:
> Hey everyone,
> 
> It's me again... the persistent telnet mod_perl newbie!
> (http://msgs.securepoint.com/cgi-bin/get/apache0205/204.html)
> 
> I have implemented my project using persistent telnet connections (one for
> each user session accessible throught the session to perform various
> functions through telnet) on win2000:
> Apache/1.3.26 (Win32) mod_perl/1.27_01-dev
> 
> Now for my next trick! 
> When I started I didn't realize that mod_perl on win32 could only handle one
> request at a time!!! This is obviously not acceptable for deployment.
> 
> So, I would like to upgrade to Apache2/mod_perl2 to take advantage of the
> multi-process mod_perl model that the _very_ kind Randy Kobes told me about
> (http://groups.google.ca/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=afv3gu%
> 24qt2%242%40canopus.cc.umanitoba.ca). However, with a multi-process model,
> I'm not sure how I will be able to keep a user's telnet-session-object
> accessible throughout multiple requests. Currently it's not a problem since
> there's only one process for ALL mod_perl requests. In Apache2/mod_perl2
> there will be more than one process so I need some sort of mapping to make
> sure my clients are aways served by the same process. Is this possible? Am I
> in way over my head (again!!) ?

It seems that you are after the same functionality as Apache::DBI, you 
want a pool of items that you want to be able to choose from. Look for 
threads::shared (perl 5.8.0), just create a shared hash with keys that 
you use for the map and the values for the actual connection objects.

If you can have the client persist the connection, you can implement a 
real protocol module. e.g., see:
http://perl.apache.org/docs/2.0/user/handlers/handlers.html#PerlProcessConnectionHandler

> Another problem is that I have also been informed that my _MUCH_ used
> apache_notes function in php will not be available to me in Apache2
> (http://bugs.php.net/bug.php?id=17557). I realize this is an Apache2 thing,
> but I was wondering if anyone here knows of a workaround that will allow my
> php scripts to communicate with mod_perl (and vice-versa) until (hopefully)
> the function is ported to Apache2.

 From what I understood mod_php in 2.0 is going to be implemented as a 
filter. Is that right? Is that the reason why notes won't work anymore? 
I don't think so. Practically there should be a problem to implement 
this feature, because you have a connection object which persists for 
the whole connection, so you should be able to register some data in 
this object and then retrieve it later in some other phase/filter.

in mod_perl handler you simply get the connectin object and stick 
something into the notes, e.g. inside request handlers:

my $r = shift;
my $c = $r->connection;
$c->notes->set(mod_perl => 'rules');

and then later for example in a mod_perl filter handler you do:

my $f = shift;
my $c = $f->connection;
my $is = $c->notes->get("mod_perl");
$f->print("mod_perl $is");

you should ask php folks why cannot they get c->notes working, the C 
datastructure is all there waiting to be used.

__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com




Persistent Net::Telnet Objects in Apache2/mod_perl2

2002-07-15 Thread French, Shawn

Hey everyone,

It's me again... the persistent telnet mod_perl newbie!
(http://msgs.securepoint.com/cgi-bin/get/apache0205/204.html)

I have implemented my project using persistent telnet connections (one for
each user session accessible throught the session to perform various
functions through telnet) on win2000:
Apache/1.3.26 (Win32) mod_perl/1.27_01-dev

Now for my next trick! 
When I started I didn't realize that mod_perl on win32 could only handle one
request at a time!!! This is obviously not acceptable for deployment.

So, I would like to upgrade to Apache2/mod_perl2 to take advantage of the
multi-process mod_perl model that the _very_ kind Randy Kobes told me about
(http://groups.google.ca/groups?dq=&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=afv3gu%
24qt2%242%40canopus.cc.umanitoba.ca). However, with a multi-process model,
I'm not sure how I will be able to keep a user's telnet-session-object
accessible throughout multiple requests. Currently it's not a problem since
there's only one process for ALL mod_perl requests. In Apache2/mod_perl2
there will be more than one process so I need some sort of mapping to make
sure my clients are aways served by the same process. Is this possible? Am I
in way over my head (again!!) ?

Another problem is that I have also been informed that my _MUCH_ used
apache_notes function in php will not be available to me in Apache2
(http://bugs.php.net/bug.php?id=17557). I realize this is an Apache2 thing,
but I was wondering if anyone here knows of a workaround that will allow my
php scripts to communicate with mod_perl (and vice-versa) until (hopefully)
the function is ported to Apache2.

Thanks in advance,

Shawn French
AcceLight Networks
613.266.4753
[EMAIL PROTECTED]





Re: Persistant references [was] Persistent Net::Telnet Objects

2002-05-31 Thread Perrin Harkins

First, there is no way to effectively pass compiled code between 
processes at this time.  It isn't likely to happen with Perl 5 because 
attempts at loading compiled bytecode from disk have usually had poor 
performance and other issues.

Second, what you're proposing is probably not a good idea unless this is 
for a small in-house project.

> What I mean is, if a request comes in for a certain form I would like to be
> able to do something like this:
> 
> my $form = &load_form($r);
> $c{$session_id}->{handler} = $form->{handler}; # <-- this being a code
> ref...
> $r->send_http_header;
> print $form;
> 
> Then when the user completes the form and resubmits:
> 
> my $handler = $c{$session_id}->{handler};
> $r->send_http_header;
> print $handler->($r);

What if the same user has multiple browser windows open and starts on a 
new form before finishing the existing form?  Remember, sessions are 
global to all browser windows.

The right thing to do here is pass the form data the old-hasioned way, 
in URLs or form fields.  Those are distinct for each browser window.

> I would like to be able to dynamically create anonymous
> subroutine handlers based on input and have them be active until the form is
> submitted, at which time they are used to process the form then discarded.

But why go to all that trouble, generating subroutines on the fly?  It 
just doesn't seem necessary for processing form input.

- Perrin




Re: Persistent Net::Telnet Objects

2002-05-31 Thread Perrin Harkins

French, Shawn wrote:
> Recall that I am using: Apache/1.3.20 (Win32) mod_perl/1.25_01-dev
> mod_ssl/2.8.4 OpenSSL/0.9.6a on Windows 2000 with PHP 4.21
> 
> Would this be why my scripts are working?

Mystery solved!  Yes, that's why.  You are running mod_perl in single 
process mode because you're on Windows, so only one request is handled 
at a time.  That means that every user will always return to the same 
Apache process, since there is only one of them!

> Does this mean that as long as I
> stay with windows I will be alright?

For certan definitions of alright, yes.  It won't be speedy if you start 
getting many concurrent requests.

- Perrin





Re: Persistant references [was] Persistent Net::Telnet Objects

2002-05-30 Thread Ryan Parr

I have thought about this, and it's something I'm willing to do if I have
to. I would much rather be able to store an actual code ref and avoid the
overhead of many string-form eval's. Is there no way to do this?

-- Ryan


- Original Message -
From: "Garth Winter Webb" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 29, 2002 11:16 PM
Subject: Re: Persistant references [was] Persistent Net::Telnet Objects


> You could just pass around a string rather than a subref:
>
> my $handler = 'sub { my $arg = @_; do_something(); }';
>
> vs
>
> my $handler = sub { my $arg = @_; do_something(); };
>
> When you want to call it later on you do it like:
>
> eval($handler)->('foo');
>
> vs
>
> $handler->('foo');
>
> Garth
>
> On Wed, 2002-05-29 at 22:17, Ryan Parr wrote:
> > I never do give enough info on the first e-mail. Thank you for bearing
with
> > me...
> >
> > What I mean is, if a request comes in for a certain form I would like to
be
> > able to do something like this:
> >
> > my $form = &load_form($r);
> > $c{$session_id}->{handler} = $form->{handler}; # <-- this being a code
> > ref...
> > $r->send_http_header;
> > print $form;
> >
> > Then when the user completes the form and resubmits:
> >
> > my $handler = $c{$session_id}->{handler};
> > $r->send_http_header;
> > print $handler->($r);
> >
> > This is definately simplified, but the idea is there. I would like to be
> > able to store anything that can be referenced and have it be available
to
> > all processes. I would like to be able to dynamically create anonymous
> > subroutine handlers based on input and have them be active until the
form is
> > submitted, at which time they are used to process the form then
discarded.
> >
> > Is this something that can be accomplished? The global hash using Perl
> > aliasing
> >
(http://thingy.kcilink.com/modperlguide/perl/Using_the_Perl_Aliasing_Feature
> > _.html) works beautifully, until of course the form is submitted to
another
> > httpd process, and I'm hoping to not have to limit myself to just one
child.
> >
> > Obviously this can't be serialized, but there has to be *some* way to do
> > this...
> >
> > -- Ryan
> >
> >
> > - Original Message -
> > From: "Ryan Parr" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Wednesday, May 29, 2002 9:16 PM
> > Subject: Persistant references [was] Persistent Net::Telnet Objects
> >
> >
> > > Along these same lines I'm seeking a way to store a code reference
into a
> > > global hash that is shared among all processes. For example:
> > >
> > > my $session_id = get_session_from_cookie($r);
> > > my $handler = $c{$session_id}->{handler};
> > >
> > > $r->send_http_header;
> > > print $handler->($r);
> > > return OK;
> > >
> > > Has anyone performed this kind of magical tidbit before? Is there some
> > main
> > > process repository that I can access?
> > >
> > > -- Ryan
> > >
> > >
> > > - Original Message -
> > > From: "Rob Mueller (fastmail)" <[EMAIL PROTECTED]>
> > > To: "French, Shawn" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > > Sent: Wednesday, May 29, 2002 5:35 PM
> > > Subject: Re: Persistent Net::Telnet Objects
> > >
> > >
> > > > Our project needed persistent socket connections open as well. There
is
> > > > supposed to be a standard mechanism to pass file descriptors between
> > unix
> > > > processes, though it's bugginess level depends on your OS. There is
a
> > perl
> > > > module for this called Socket::PassAccessRights. So what you can do
is
> > > > create a daemon process that just hangs round holding socket
connections
> > > > open, like a socket cache basically, and passing them back and forth
> > > between
> > > > Apache processes based on some session ID or user ID or the like.
> > > >
> > > > Your daemon ends up looking something like this (with lots more
error
> > > > checking of course)
> > > >
> > > > my %sockmap;
> > > > while (1) {
> > > >   my $clientsock = $listen->accept();
> > > >   chomp(my $sessionid = <$clientsock>);
> > > >   my $cachesock = ($sockmap

Re: Persistent Net::Telnet Objects

2002-05-30 Thread Keith G. Murphy

"French, Shawn" wrote:
> 
> I just found this: http://www.devshed.com/Talk/Books/ProApache/page2.html
> 
> "On Windows platforms, Apache does not fork; consequently, the directives
> for controlling the number of processes or their lifetime have no effect.
> Instead, Apache runs as a multi-threaded process"
> 
> Recall that I am using: Apache/1.3.20 (Win32) mod_perl/1.25_01-dev
> mod_ssl/2.8.4 OpenSSL/0.9.6a on Windows 2000 with PHP 4.21
> 
> Would this be why my scripts are working? Does this mean that as long as I
> stay with windows I will be alright?
> 
I'm guessing that it has more to do with having "KeepAlive On" (in
httpd.conf) and a client that supports HTTP 1.1.

For a test, try "KeepAlive Off", or use a client that doesn't support
HTTP 1.1 (Netscape 4.x, for example).



RE: Persistent Net::Telnet Objects

2002-05-30 Thread Jim Helm

It it possible that KeepAlives are what's making this work?  If the user
is active enough, in theory, they would always be connected to the same
httpd process...

Jim

--
James Helm - Solaris System Administrator   [EMAIL PROTECTED]
WNS National Operations - Core Services [EMAIL PROTECTED]
AT&T Wireless Services Inc. (425) 288-4395 (Desk) 
3555 Monte Villa Pkwy, Bothell, WA  98021   (206) 618-0438 (Cell)  

> -Original Message-
> From: French, Shawn [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, May 29, 2002 1:50 PM
> To: 'Perrin Harkins'
> Cc: [EMAIL PROTECTED]
> Subject: RE: Persistent Net::Telnet Objects
> 
> 
> Perrin wrote:
> > I can't see how it could be working now
> 
> That makes two of us!
> 
> > You're probably opening new telnet connections from each apache 
> > process.
> 
> I know that I am not since they are continuing to log to the 
> same dump file, and my code (as stated in previous message) 
> simply goes to the hash and takes the object.
> 
> > That won't work, since you can't control which process will handle
> > requests from the client.
> 
> OK, is there a way to make sure that there is just one 
> process? This site is not for milions of users, only 10 - 20.
> 
> I'm sure that others have had to keep persistent sockets 
> and/or filehandles on their server, and I really don't see 
> how my problem is any different...
> 
> Please, can anybody help me?
> Shawn
> 




RE: Persistent Net::Telnet Objects

2002-05-30 Thread French, Shawn

I just found this: http://www.devshed.com/Talk/Books/ProApache/page2.html

"On Windows platforms, Apache does not fork; consequently, the directives
for controlling the number of processes or their lifetime have no effect.
Instead, Apache runs as a multi-threaded process"

Recall that I am using: Apache/1.3.20 (Win32) mod_perl/1.25_01-dev
mod_ssl/2.8.4 OpenSSL/0.9.6a on Windows 2000 with PHP 4.21

Would this be why my scripts are working? Does this mean that as long as I
stay with windows I will be alright?

I realize (as Medi Montaseri pointed out) that my scripts might not be too
secure (ie. hijacking a telnet session) however I am only concerned about
getting this working, and making sure it will remain working, as it will be
run behind a firewall in a corporate intranet.

For now I will continue coding with my current architecture hoping that the
above mentioned information is correct.

Thanks for all the help!
Shawn



Re: Persistent Net::Telnet Objects

2002-05-29 Thread Medi Montaseri


Perhaps you can put a System V message Queue in front of both Telnet
connections, this way producers can place their messages in the queue
asynchronously , and the backend (consumer) can pick them up in a FIFO.
Also, try using Net::SSH::Perl. The Net::Telnet does not give your things
like
STDOUT, vs STDERR, vs Exit code. Net::Telnet puts everything in one
channel.
The Security is yet another issue, specially when the session could
be open
and idle for exessive amount of time. Your session can be hijacked
easily.
"French, Shawn" wrote:
Vitals:
Apache/1.3.20 (Win32) mod_perl/1.25_01-dev mod_ssl/2.8.4 OpenSSL/0.9.6a
on
Windows 2000 with PHP 4.21
I am working on a project that requires me to have two telnet objects
per
user session opened, and accessible throughout the user's session.
I have
looked at Apache::Session and many other solutions but my problem is
that to
keep a Net::Telnet object, I need to keep open sockets and filehandles,
so I
cannot serialize the object and store it in a database or file.
Currently I have similar code working flawlessly:
###
# "startup.pl" - called when apache starts (ie. PerlRequire
"d:/Apache/conf/startup.pl")
##
use MySite::Session;
###
# "Session.pm"
##
@EXPORT = qw( %sessionHash );
our %sessionHash;
###
# "init_session.pl" - called IN MOD_PERL when a new session is requested
##
use MySite::Session;
$sessionHash{$session_id . "_telnetObj"} = Net::Telnet->new();
###
# "dostuff.pl" - called IN MOD_PERL many time throughout the session
##
use MySite::Session;
my telnetObj = $sessionHash{$session_id . "_telnetObj"};
bless (\$telnetObj, "Net::Telnet");
Although this is working right now, I don't know enough [ anything?
:) ]
about Apache or mod_perl to be sure that this will work in the future.
What
I am really concerned about is that the telnetObj will only be accessible
from scripts run by the same child process as that which created and
saved
it.
Is there a better way to do this?
Thanks,
Shawn French

-- 
-
Medi Montaseri   [EMAIL PROTECTED]
Unix Distributed Systems Engineer    HTTP://www.CyberShell.com
CyberShell Engineering
-
 


Re: Persistant references [was] Persistent Net::Telnet Objects

2002-05-29 Thread Garth Winter Webb

You could just pass around a string rather than a subref:

my $handler = 'sub { my $arg = @_; do_something(); }';

vs

my $handler = sub { my $arg = @_; do_something(); };

When you want to call it later on you do it like:

eval($handler)->('foo');

vs

$handler->('foo');

Garth

On Wed, 2002-05-29 at 22:17, Ryan Parr wrote:
> I never do give enough info on the first e-mail. Thank you for bearing with
> me...
> 
> What I mean is, if a request comes in for a certain form I would like to be
> able to do something like this:
> 
> my $form = &load_form($r);
> $c{$session_id}->{handler} = $form->{handler}; # <-- this being a code
> ref...
> $r->send_http_header;
> print $form;
> 
> Then when the user completes the form and resubmits:
> 
> my $handler = $c{$session_id}->{handler};
> $r->send_http_header;
> print $handler->($r);
> 
> This is definately simplified, but the idea is there. I would like to be
> able to store anything that can be referenced and have it be available to
> all processes. I would like to be able to dynamically create anonymous
> subroutine handlers based on input and have them be active until the form is
> submitted, at which time they are used to process the form then discarded.
> 
> Is this something that can be accomplished? The global hash using Perl
> aliasing
> (http://thingy.kcilink.com/modperlguide/perl/Using_the_Perl_Aliasing_Feature
> _.html) works beautifully, until of course the form is submitted to another
> httpd process, and I'm hoping to not have to limit myself to just one child.
> 
> Obviously this can't be serialized, but there has to be *some* way to do
> this...
> 
> -- Ryan
> 
> 
> ----- Original Message -
> From: "Ryan Parr" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, May 29, 2002 9:16 PM
> Subject: Persistant references [was] Persistent Net::Telnet Objects
> 
> 
> > Along these same lines I'm seeking a way to store a code reference into a
> > global hash that is shared among all processes. For example:
> >
> > my $session_id = get_session_from_cookie($r);
> > my $handler = $c{$session_id}->{handler};
> >
> > $r->send_http_header;
> > print $handler->($r);
> > return OK;
> >
> > Has anyone performed this kind of magical tidbit before? Is there some
> main
> > process repository that I can access?
> >
> > -- Ryan
> >
> >
> > - Original Message -
> > From: "Rob Mueller (fastmail)" <[EMAIL PROTECTED]>
> > To: "French, Shawn" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > Sent: Wednesday, May 29, 2002 5:35 PM
> > Subject: Re: Persistent Net::Telnet Objects
> >
> >
> > > Our project needed persistent socket connections open as well. There is
> > > supposed to be a standard mechanism to pass file descriptors between
> unix
> > > processes, though it's bugginess level depends on your OS. There is a
> perl
> > > module for this called Socket::PassAccessRights. So what you can do is
> > > create a daemon process that just hangs round holding socket connections
> > > open, like a socket cache basically, and passing them back and forth
> > between
> > > Apache processes based on some session ID or user ID or the like.
> > >
> > > Your daemon ends up looking something like this (with lots more error
> > > checking of course)
> > >
> > > my %sockmap;
> > > while (1) {
> > >   my $clientsock = $listen->accept();
> > >   chomp(my $sessionid = <$clientsock>);
> > >   my $cachesock = ($sockmap{$sessionid} ||= opennewsock());
> > >   Socket::PassAccessRights::sendfd(fileno($clientsock),
> > fileno($cachesock));
> > >   $clientsock->close();
> > > }
> > >
> > > And in your mod_perl code you do something like:
> > >
> > >   my $serversock = IO::Socket::INET->new(Server => 'localhost', Port =>
> > > SOCKETPOOLPORT);
> > >   print $serversock $sessionid, "\n";
> > >   my $Fd = Socket::PassAccessRights::recvfd(fileno($serversock));
> > >   open(my $realsocket, "<&=$Fd");
> > >   fcntl($realsocket, F_SETFD, 0);
> > >   my $ofh = select($realsocket); $| = 1; select ($ofh);
> > >
> > > If you do some experimenting, you'll get something that works, you'll
> also
> > > find lots of cases that don't.
> > >
> > > Rob
> > >
> >

Re: Persistant references [was] Persistent Net::Telnet Objects

2002-05-29 Thread Ryan Parr

I never do give enough info on the first e-mail. Thank you for bearing with
me...

What I mean is, if a request comes in for a certain form I would like to be
able to do something like this:

my $form = &load_form($r);
$c{$session_id}->{handler} = $form->{handler}; # <-- this being a code
ref...
$r->send_http_header;
print $form;

Then when the user completes the form and resubmits:

my $handler = $c{$session_id}->{handler};
$r->send_http_header;
print $handler->($r);

This is definately simplified, but the idea is there. I would like to be
able to store anything that can be referenced and have it be available to
all processes. I would like to be able to dynamically create anonymous
subroutine handlers based on input and have them be active until the form is
submitted, at which time they are used to process the form then discarded.

Is this something that can be accomplished? The global hash using Perl
aliasing
(http://thingy.kcilink.com/modperlguide/perl/Using_the_Perl_Aliasing_Feature
_.html) works beautifully, until of course the form is submitted to another
httpd process, and I'm hoping to not have to limit myself to just one child.

Obviously this can't be serialized, but there has to be *some* way to do
this...

-- Ryan


- Original Message -
From: "Ryan Parr" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 29, 2002 9:16 PM
Subject: Persistant references [was] Persistent Net::Telnet Objects


> Along these same lines I'm seeking a way to store a code reference into a
> global hash that is shared among all processes. For example:
>
> my $session_id = get_session_from_cookie($r);
> my $handler = $c{$session_id}->{handler};
>
> $r->send_http_header;
> print $handler->($r);
> return OK;
>
> Has anyone performed this kind of magical tidbit before? Is there some
main
> process repository that I can access?
>
> -- Ryan
>
>
> - Original Message -
> From: "Rob Mueller (fastmail)" <[EMAIL PROTECTED]>
> To: "French, Shawn" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Wednesday, May 29, 2002 5:35 PM
> Subject: Re: Persistent Net::Telnet Objects
>
>
> > Our project needed persistent socket connections open as well. There is
> > supposed to be a standard mechanism to pass file descriptors between
unix
> > processes, though it's bugginess level depends on your OS. There is a
perl
> > module for this called Socket::PassAccessRights. So what you can do is
> > create a daemon process that just hangs round holding socket connections
> > open, like a socket cache basically, and passing them back and forth
> between
> > Apache processes based on some session ID or user ID or the like.
> >
> > Your daemon ends up looking something like this (with lots more error
> > checking of course)
> >
> > my %sockmap;
> > while (1) {
> >   my $clientsock = $listen->accept();
> >   chomp(my $sessionid = <$clientsock>);
> >   my $cachesock = ($sockmap{$sessionid} ||= opennewsock());
> >   Socket::PassAccessRights::sendfd(fileno($clientsock),
> fileno($cachesock));
> >   $clientsock->close();
> > }
> >
> > And in your mod_perl code you do something like:
> >
> >   my $serversock = IO::Socket::INET->new(Server => 'localhost', Port =>
> > SOCKETPOOLPORT);
> >   print $serversock $sessionid, "\n";
> >   my $Fd = Socket::PassAccessRights::recvfd(fileno($serversock));
> >   open(my $realsocket, "<&=$Fd");
> >   fcntl($realsocket, F_SETFD, 0);
> >   my $ofh = select($realsocket); $| = 1; select ($ofh);
> >
> > If you do some experimenting, you'll get something that works, you'll
also
> > find lots of cases that don't.
> >
> > Rob
> >
> > - Original Message -
> > From: "French, Shawn" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, May 30, 2002 3:53 AM
> > Subject: Persistent Net::Telnet Objects
> >
> >
> > > Vitals:
> > > Apache/1.3.20 (Win32) mod_perl/1.25_01-dev mod_ssl/2.8.4
OpenSSL/0.9.6a
> on
> > > Windows 2000 with PHP 4.21
> > >
> > > I am working on a project that requires me to have two telnet objects
> per
> > > user session opened, and accessible throughout the user's session. I
> have
> > > looked at Apache::Session and many other solutions but my problem is
> that
> > to
> > > keep a Net::Telnet object, I need to keep open sockets and
filehandles,
> so
> > I
> > > cannot serialize the object and store it in a database 

Persistant references [was] Persistent Net::Telnet Objects

2002-05-29 Thread Ryan Parr

Along these same lines I'm seeking a way to store a code reference into a
global hash that is shared among all processes. For example:

my $session_id = get_session_from_cookie($r);
my $handler = $c{$session_id}->{handler};

$r->send_http_header;
print $handler->($r);
return OK;

Has anyone performed this kind of magical tidbit before? Is there some main
process repository that I can access?

-- Ryan


- Original Message -
From: "Rob Mueller (fastmail)" <[EMAIL PROTECTED]>
To: "French, Shawn" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, May 29, 2002 5:35 PM
Subject: Re: Persistent Net::Telnet Objects


> Our project needed persistent socket connections open as well. There is
> supposed to be a standard mechanism to pass file descriptors between unix
> processes, though it's bugginess level depends on your OS. There is a perl
> module for this called Socket::PassAccessRights. So what you can do is
> create a daemon process that just hangs round holding socket connections
> open, like a socket cache basically, and passing them back and forth
between
> Apache processes based on some session ID or user ID or the like.
>
> Your daemon ends up looking something like this (with lots more error
> checking of course)
>
> my %sockmap;
> while (1) {
>   my $clientsock = $listen->accept();
>   chomp(my $sessionid = <$clientsock>);
>   my $cachesock = ($sockmap{$sessionid} ||= opennewsock());
>   Socket::PassAccessRights::sendfd(fileno($clientsock),
fileno($cachesock));
>   $clientsock->close();
> }
>
> And in your mod_perl code you do something like:
>
>   my $serversock = IO::Socket::INET->new(Server => 'localhost', Port =>
> SOCKETPOOLPORT);
>   print $serversock $sessionid, "\n";
>   my $Fd = Socket::PassAccessRights::recvfd(fileno($serversock));
>   open(my $realsocket, "<&=$Fd");
>   fcntl($realsocket, F_SETFD, 0);
>   my $ofh = select($realsocket); $| = 1; select ($ofh);
>
> If you do some experimenting, you'll get something that works, you'll also
> find lots of cases that don't.
>
> Rob
>
> - Original Message -
> From: "French, Shawn" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, May 30, 2002 3:53 AM
> Subject: Persistent Net::Telnet Objects
>
>
> > Vitals:
> > Apache/1.3.20 (Win32) mod_perl/1.25_01-dev mod_ssl/2.8.4 OpenSSL/0.9.6a
on
> > Windows 2000 with PHP 4.21
> >
> > I am working on a project that requires me to have two telnet objects
per
> > user session opened, and accessible throughout the user's session. I
have
> > looked at Apache::Session and many other solutions but my problem is
that
> to
> > keep a Net::Telnet object, I need to keep open sockets and filehandles,
so
> I
> > cannot serialize the object and store it in a database or file.
> >
> > Currently I have similar code working flawlessly:
> > ###
> > # "startup.pl" - called when apache starts (ie. PerlRequire
> > "d:/Apache/conf/startup.pl")
> > ##
> > use MySite::Session;
> >
> > ###
> > # "Session.pm"
> > ##
> > @EXPORT = qw( %sessionHash );
> > our %sessionHash;
> >
> > ###
> > # "init_session.pl" - called IN MOD_PERL when a new session is requested
> > ##
> > use MySite::Session;
> > $sessionHash{$session_id . "_telnetObj"} = Net::Telnet->new();
> >
> > ###
> > # "dostuff.pl" - called IN MOD_PERL many time throughout the session
> > ##
> > use MySite::Session;
> > my telnetObj = $sessionHash{$session_id . "_telnetObj"};
> > bless (\$telnetObj, "Net::Telnet");
> >
> > Although this is working right now, I don't know enough [ anything? :) ]
> > about Apache or mod_perl to be sure that this will work in the future.
> What
> > I am really concerned about is that the telnetObj will only be
accessible
> > from scripts run by the same child process as that which created and
saved
> > it.
> >
> > Is there a better way to do this?
> >
> > Thanks,
> > Shawn French
> >
> >
>




Re: Persistent Net::Telnet Objects

2002-05-29 Thread Rob Mueller (fastmail)

Our project needed persistent socket connections open as well. There is
supposed to be a standard mechanism to pass file descriptors between unix
processes, though it's bugginess level depends on your OS. There is a perl
module for this called Socket::PassAccessRights. So what you can do is
create a daemon process that just hangs round holding socket connections
open, like a socket cache basically, and passing them back and forth between
Apache processes based on some session ID or user ID or the like.

Your daemon ends up looking something like this (with lots more error
checking of course)

my %sockmap;
while (1) {
  my $clientsock = $listen->accept();
  chomp(my $sessionid = <$clientsock>);
  my $cachesock = ($sockmap{$sessionid} ||= opennewsock());
  Socket::PassAccessRights::sendfd(fileno($clientsock), fileno($cachesock));
  $clientsock->close();
}

And in your mod_perl code you do something like:

  my $serversock = IO::Socket::INET->new(Server => 'localhost', Port =>
SOCKETPOOLPORT);
  print $serversock $sessionid, "\n";
  my $Fd = Socket::PassAccessRights::recvfd(fileno($serversock));
  open(my $realsocket, "<&=$Fd");
  fcntl($realsocket, F_SETFD, 0);
  my $ofh = select($realsocket); $| = 1; select ($ofh);

If you do some experimenting, you'll get something that works, you'll also
find lots of cases that don't.

Rob

- Original Message -
From: "French, Shawn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 30, 2002 3:53 AM
Subject: Persistent Net::Telnet Objects


> Vitals:
> Apache/1.3.20 (Win32) mod_perl/1.25_01-dev mod_ssl/2.8.4 OpenSSL/0.9.6a on
> Windows 2000 with PHP 4.21
>
> I am working on a project that requires me to have two telnet objects per
> user session opened, and accessible throughout the user's session. I have
> looked at Apache::Session and many other solutions but my problem is that
to
> keep a Net::Telnet object, I need to keep open sockets and filehandles, so
I
> cannot serialize the object and store it in a database or file.
>
> Currently I have similar code working flawlessly:
> ###
> # "startup.pl" - called when apache starts (ie. PerlRequire
> "d:/Apache/conf/startup.pl")
> ##
> use MySite::Session;
>
> ###
> # "Session.pm"
> ##
> @EXPORT = qw( %sessionHash );
> our %sessionHash;
>
> ###
> # "init_session.pl" - called IN MOD_PERL when a new session is requested
> ##
> use MySite::Session;
> $sessionHash{$session_id . "_telnetObj"} = Net::Telnet->new();
>
> ###
> # "dostuff.pl" - called IN MOD_PERL many time throughout the session
> ##
> use MySite::Session;
> my telnetObj = $sessionHash{$session_id . "_telnetObj"};
> bless (\$telnetObj, "Net::Telnet");
>
> Although this is working right now, I don't know enough [ anything? :) ]
> about Apache or mod_perl to be sure that this will work in the future.
What
> I am really concerned about is that the telnetObj will only be accessible
> from scripts run by the same child process as that which created and saved
> it.
>
> Is there a better way to do this?
>
> Thanks,
> Shawn French
>
>




RE: Persistent Net::Telnet Objects

2002-05-29 Thread mod_perl

Maybe you can tell us more about the project (e.g. why 
telnet ?) so there will come many bad advices ? :-)

Peter Bi
 
> Perrin wrote:
> > I can't see how it could be working now
> 
> That makes two of us!
> 
> > You're probably opening new telnet connections from each apache process.
> 
> I know that I am not since they are continuing to log to the same dump file,
> and my code (as stated in previous message) simply goes to the hash and
> takes the object.
> 
> > That won't work, since you can't control which process will handle 
> > requests from the client.
> 
> OK, is there a way to make sure that there is just one process? This site is
> not for milions of users, only 10 - 20.
> 
> I'm sure that others have had to keep persistent sockets and/or filehandles
> on their server, and I really don't see how my problem is any different...
> 
> Please, can anybody help me?
> Shawn



RE: Persistent Net::Telnet Objects

2002-05-29 Thread French, Shawn

Perrin wrote:
> I can't see how it could be working now

That makes two of us!

> You're probably opening new telnet connections from each apache process.

I know that I am not since they are continuing to log to the same dump file,
and my code (as stated in previous message) simply goes to the hash and
takes the object.

> That won't work, since you can't control which process will handle 
> requests from the client.

OK, is there a way to make sure that there is just one process? This site is
not for milions of users, only 10 - 20.

I'm sure that others have had to keep persistent sockets and/or filehandles
on their server, and I really don't see how my problem is any different...

Please, can anybody help me?
Shawn



Re: Persistent Net::Telnet Objects

2002-05-29 Thread Perrin Harkins

French, Shawn wrote:
> Although this is working right now, I don't know enough [ anything? :) ]
> about Apache or mod_perl to be sure that this will work in the future.

I can't see how it could be working now, unless it is actually creating 
a new Telnet object on every request.  Your %sessionHash is not shared 
between processes and you have no control over which process will handle 
any request.  You're probably opening new telnet connections from each 
apache process.

> What
> I am really concerned about is that the telnetObj will only be accessible
> from scripts run by the same child process as that which created and saved
> it.

That won't work, since you can't control which process will handle 
requests from the client.

> Is there a better way to do this?

You could write a web server in Perl, which would run a separate 
persistent process for each client on a different port.  Randal wrote a 
column about that: http://www.stonehenge.com/merlyn/WebTechniques/col23.html

You could also use this technique to make a sort of telnet server, and 
hide that server behind Apache/mod_perl, i.e. clients talk to mod_perl 
which talks to the telnet server.

Of course the simplest approach would be to just let each Apache process 
open telnet sessions as needed.

- Perrin







Persistent Net::Telnet Objects

2002-05-29 Thread French, Shawn

Vitals:
Apache/1.3.20 (Win32) mod_perl/1.25_01-dev mod_ssl/2.8.4 OpenSSL/0.9.6a on
Windows 2000 with PHP 4.21

I am working on a project that requires me to have two telnet objects per
user session opened, and accessible throughout the user's session. I have
looked at Apache::Session and many other solutions but my problem is that to
keep a Net::Telnet object, I need to keep open sockets and filehandles, so I
cannot serialize the object and store it in a database or file.

Currently I have similar code working flawlessly:
###
# "startup.pl" - called when apache starts (ie. PerlRequire
"d:/Apache/conf/startup.pl")
##
use MySite::Session;

###
# "Session.pm"
##
@EXPORT = qw( %sessionHash );
our %sessionHash;

###
# "init_session.pl" - called IN MOD_PERL when a new session is requested
##
use MySite::Session;
$sessionHash{$session_id . "_telnetObj"} = Net::Telnet->new();

###
# "dostuff.pl" - called IN MOD_PERL many time throughout the session
##
use MySite::Session;
my telnetObj = $sessionHash{$session_id . "_telnetObj"};
bless (\$telnetObj, "Net::Telnet");

Although this is working right now, I don't know enough [ anything? :) ]
about Apache or mod_perl to be sure that this will work in the future. What
I am really concerned about is that the telnetObj will only be accessible
from scripts run by the same child process as that which created and saved
it.

Is there a better way to do this?

Thanks,
Shawn French