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

Re: error_log contents

2002-05-18 Thread Garth Winter Webb

Type this:

$ perl -de 1

And tell me if it looks familiar to you.  Looks like somehow, somewhere,
the debugging flag is being set...

G

On Sat, 2002-05-18 at 14:11, Gregory Matthews wrote:
> I am getting the following repeating code in my error log in doing some 
> testing on my script:
> 
> DB<1>   DB<1>   DB<1>   DB<1>   DB<1>   DB<1>   DB<1>   DB<1>
> 
> Does anyone know what this means?  It seems to go away when I restart apache.
> 
> Gregory
> 
> 
-- 
,---.
  Garth Webb  
  [EMAIL PROTECTED]
  C: 415.652.7688 
  H: 415.701.0568 
`==='




Re: How to get two perl namespaces in apache

2002-03-28 Thread Garth Winter Webb

You just need to fire up two separate apaches, each with their own
conf.  So basically you have:

/usr/local/apache_prod
/usr/local/apache_dev

These can actually share the same bin and lib directories; everything is
still installed at '/usr/local/apache' and you symlink the directories
you want to have in common.  You also need separate copies of apachectl
that fire up the httpd's so that they point at the right httpd.conf and
have the right server root.

Garth

On Tue, 2002-03-26 at 11:16, Thomas K. Burkholder wrote:
> Hi there-
> 
> Apologies if this gets sent twice - I sent a message yesterday, but it 
> seems to have vanished into the ether.
> 
> I'd like to run the production server of my mod_perl project 
> (http://www.areaj.org/areaj) on the same machine as my development 
> server.  Clearly they have the same module names so I have to somehow 
> run them in two different environments - I don't think running them on 
> two different virtual servers is going to do it, right?  Doesn't apache 
> just start one perl "runtime"?  Please tell me if I'm mistaken about 
> that.
> 
> So, I guess I'm wondering if there's an easy way to have two completely 
> separate apache configurations running on the same machine (listening on 
> different ports obviously).
> 
> Any help greatly appreciated.
> 
> Thanks,
> 
> //Thomas
> Thomas K. Burkholder
> 
-- 
,---.
  Garth Webb  
  [EMAIL PROTECTED]
  C: 415.652.7688 
  H: 415.701.0568 
`==='




Re: Can't open perl script " -spi.bak"

2002-03-22 Thread Garth Winter Webb

On Fri, 2002-03-22 at 12:57, Robert Landrum wrote:

> >That's is very weird, because this code doesn't seem to work:
> >
> >perl -e 'system("perl", " -e1") == 0 or die "oops"'
> 
> Actually, that's not all that weird.  Most shells take care of 
> stripping out garbage before setting the argument list.  Since 
> system(LIST) doesn't use the shell, it's passing perl the literal " 
> -e1" which perl won't recognize as a command line option (and 
> correctly so in my opinion).

Actually this isn't standard behavior.  I can't think of a situation
where I would want to use system to concatanate a string for me rather
than interpreting the string as an argument and act accordingly.  If you
check 'perldoc -f system', this is exactly what system is supposed to do
when given a program name and a list of arguments, so it looks like
'systetm' may be buggy in the win32 version of perl

G




Re: Subroutines taking time to return..

2002-03-20 Thread Garth Winter Webb

Have you tried using Apache::DProf?  Using this is a lot easier than
trying to add tons of debug messages.  If you  haven't used it or the
regular DProf, it does what your doing automatically.  It  generates a
file of data that you run 'dprofpp' on and you can get a list of the top
10 or so most time consuming functions.  Using Apache::DProf usually
reveals time consuming methods in my code that I would never have
expected to take so long.
In your case, however thourough you were in placing debug statements,
its possible (and likely) that you've missed the key subroutine. 

G

On Wed, 2002-03-20 at 09:59, David Brown wrote:
> I've been profiling my MySQL driven Mod_Perl website by adding debug
> messages throughout the code which relays what time has elapsed since the
> script was invoked (using Time::HiRes)
> 
> Now the script is pretty whizzy, serving up complete pages in circa 0.010
> seconds.
> 
> I got to wondering how those 0.010 were being made up.  Interestingly, all
> of the database access is complete within 0.002  so I thought where do the
> other 0.008 come from ?
> 
> I found the following happened (pseudo code)
> 
> # Checkpoint A - Elapsed : 0.000
> 
> &buildpage;
> 
> # Checkpoint D - Elapsed 0.010 seconds
> 
> sub buildpage
> {
>   # Checkpoint B - Elapsed: 0.001
> 
>   # Do some DB accessing etc. make a nice webpage
> 
>   # Checkpoint C - Elapsed 0.002
> }
> 
> --
> 
> I expected all the complicated DB access stuff to make up the time, but
> instead it seems to be consuming 0.005 in returning from the subroutine to
> the main script.
> 
> What's that all about ?
> 
> Points:
> 
> 1. A global variable exists throughout the script to build the webpage
> 2. Global file handles are used to access the DB (to retain across
> subsequent requests)
> 3. No LOCAL or MY variables are defined in the subroutine.
> 4. As the webpage is being built into a global variable, the "buildpage"
> subroutine doesn't RETURN a value to the calling script.
> 
> It SEEMS the subroutine is taking an inordinate amount of time returning to
> the main procedure.. why would this be ?
> 
> ( I'm running Free/BSD, Apache/1.3.22, Mod_perl 1.26 )
> 
> 
> 
> 





Re: [OT][ANNOUNCE] The New "mod_perl" logo - results now in...

2002-03-16 Thread Garth Winter Webb

On Sat, 2002-03-16 at 08:01, [EMAIL PROTECTED] wrote:

> Recently I had a discussion with a Java programmer, who said that
> mod_perl is a try to save the obsolete language Perl. His argument was
> that only Java programmers are searched, especially here in Europe.

Interesting.  I have a friend that works for Sun whos job it is to find
companies and products that use Java and compile them into a database of
success stories.  His job has become increasingly difficult over the
past year.  Arguments about being obsolete aside, of Java and Perl, one
language is seems to be growing and one seems to be dying...


 





Re: problems returning a hash of hashes using mod_perl

2002-03-14 Thread Garth Winter Webb

On Thu, 2002-03-14 at 10:46, [EMAIL PROTECTED] wrote:

> code:
> 
> |  return %Actions::Vars::config{$conf}; |
> 
>-

You are not access the hash with the proper syntax:

%Actions::Vars::config

refers to the entire config hash, while:

$Actions::Vars::config{$conf}

will return you a value from that hash.  Notice the leading '%' has been
replaced with a '$'.  Read the 'perldsc' man page:

man perldsc

G