Re: Variables

2003-07-21 Thread Perrin Harkins
Dennis Stout wrote:
Is there a way I could get these variables populated on server start and never
loaded again unless the database was changed?  So in my subroutine for posting
an event that changed it I could call repopulate_queue_hash and have it redo
the hash, so changes still happened without a restart, but the hash itself is
just passed from the root apache process to the children?
You can load it into globals at startup and their values will be shared 
by all children until you write to them.  You could also load it 
separately in each child process in the init hook.  However, you'd 
probably be better off using MLDBM::Sync, so that all changes are shared 
immediately.  It's quite fast, and since it uses a tied interface it 
would be easy to switch your code to use globals if it turns out not be 
fast enough.

- Perrin



Re: Variables

2003-07-21 Thread Dennis Stout
  Is there a way I could get these variables populated on server start and
never
  loaded again unless the database was changed?  So in my subroutine for
posting
  an event that changed it I could call repopulate_queue_hash and have it
redo
  the hash, so changes still happened without a restart, but the hash itself
is
  just passed from the root apache process to the children?

 You can load it into globals at startup and their values will be shared
 by all children until you write to them.  You could also load it

So in startup.perl put

my %queue_list = list_queues;
my %tech_list = list_techs;

and so on?

Then each process would get a copy of the hash?

 separately in each child process in the init hook.  However, you'd

If I did that, then I'd want a few children processes at a time and also with
a few amount of requests per child...  Boy am I ever glad this'll be moved off
my box once it's finsihed ;)

 probably be better off using MLDBM::Sync, so that all changes are shared
 immediately.  It's quite fast, and since it uses a tied interface it
 would be easy to switch your code to use globals if it turns out not be
 fast enough.

After reading the perldoc for MLDBM, and reviewing my deadline for the project
of today, I think I'll just use globals for now.  But once I meet get the
management satisified, I'll be moved into a enhancment phase of hte project,
instead of a devel phase, and I'll implement it then to see how well it works.

Thanks :)



Re: Variables

2003-07-21 Thread Perrin Harkins
Dennis Stout wrote:
So in startup.perl put

my %queue_list = list_queues;
my %tech_list = list_techs;
and so on?

Then each process would get a copy of the hash?
No, those are lexicals, not globals.  Something like this:

package MyCompany::Globals;
use vars qw(%queue_list %tech_list);
%queue_list = list_queues;
%tech_list = list_techs;
Then from other code you can use them as %MyCompany::Globals::queue_list.

After reading the perldoc for MLDBM, and reviewing my deadline for the project
of today, I think I'll just use globals for now.
MLDBM::Sync is really easy to use, but if its okay for the data to be 
out of date then the globals thing is fine.  I suggest you avoid 
shenanigans with killing off processes quickly, since your performance 
would be terrible.  Instead, create a cleanup handler which runs after 
each request.  Keep a timestamp (a global variable that will persist) in 
each handler of how long it's been since you last updated the data.  If 
it's longer than 5 minutes, refresh the data.  The cleanup handler runs 
after the client is disconnected, so it doesn't matter if it takes a few 
seconds.

- Perrin



RE: variables not changing with modperl??

2002-08-13 Thread david . morgan


I'm sure someone will correct me if I'm wrong...
But, variables in the initial section (ie outside of a function) in the main
package will stay in scope all the time.  This means that it will retain the
value from a previous request- which might be giving you these problems.

As Perrin Harkins wrote, there are various solutions documented in the FAQ.
You need to read these and follow one of the methods.

 Read this:

http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my___
Scoped_Variable_in_Nested_Subroutines
 
 - Perrin


Personally I use the CGI::Application framework, which I find gives a really
nice framework to develop applications in.  Each application is a package,
and each run mode  is a sub which means you don't get any of these scope
problems.

Good luck,
David.

Mae’r neges e-bost hon ac unrhyw ffeiliau sydd ynghlwm wrthi yn gwbl gyfrinachol ac 
wedi’u bwriadu at sylw yr unigolyn neu’r endid y maent wedi eu cyfeirio ato yn unig. 
Gallant gynnwys gwybodaeth sy’n freintiedig yn gyfreithiol a/neu’n gyfrinachol ac os 
nad chi yw’r sawl y cyfeiriwyd y neges ato, yna peidiwch â chopio, dosbarthu na 
chymryd unrhyw gamau o ganlyniad a gan ddibynnu arni. Os ydych wedi derbyn y neges 
e-bost hon ar gam, a wnewch chi ein hysbysu o hyn cyn gynted â phosib a’i dileu os 
gwelwch yn dda. Barn neu safbwyntiau’r awdur yw’r rhai a fynegir yn y neges e-bost hon 
ac/neu’n unrhyw atodiadau ac nid ydynt yn adlewyrchu o anghenraid barn neu safbwyntiau 
S4C.

This e-mail message and any files attached are strictly confidential and intended 
solely for the attention of the person or entity to whom they are addressed. They may 
contain legally privileged and/or confidential information and if you are not the 
addressee, you should not copy, distribute nor take any action in reliance on them. If 
you have received this e-mail message in error, please notify us as soon as possible 
and delete it. The views and opinions expressed in this e-mail message and any 
attachments are the author’s own and they do not reflect necessarily the views and 
opinions of S4C.




Re: variables not changing with modperl??

2002-08-13 Thread darren chamberlain

* Michael Drons [EMAIL PROTECTED] [2002-08-13 01:55]:
 Thanks for the link.  I actually don't use functions.
 Everything is mostly in MAIN.  Here is a snip of code:

 #!/usr/bin/perl -wT
 use strict;
 print body;
 my $r = Apache-request;
 $r-content_type(text/html);
 $r-status(200);
 my $auth_type = $r-auth_type;
 $cookie=$auth_type-key;
 ($user,$hash)=split(/:/,$cookie);
 read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
 my @pairs = split(//, $buffer);
 foreach my $pair (@pairs) {
 
 }

 What I am doing wrong?  Everytime the script runs the
 values of the variables coming in change.  Should I
 use the delete function and delete all of the
 variables at the end of the script?  @pairs is what
 should change, but sometimes does not.  I have tried
 to add a undef @pairs before the split, but no luck.

Are you sure that this is the code that is running?  It doesn't compile:

  $ perl
  #!/usr/bin/perl -wT
  use strict;
  print body;
  my $r = Apache-request;
  $r-content_type(text/html);
  $r-status(200);
  my $auth_type = $r-auth_type;
  $cookie=$auth_type-key;
  ($user,$hash)=split(/:/,$cookie);
  read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
  my @pairs = split(//, $buffer);
  foreach my $pair (@pairs) { }
  Global symbol $cookie requires explicit package name at - line 7.
  Global symbol $user requires explicit package name at - line 8.
  Global symbol $hash requires explicit package name at - line 8.
  Global symbol $cookie requires explicit package name at - line 8.
  Execution of - aborted due to compilation errors

Make those global symbols ($cookie, $user, and $hash) lexical (declare
with my) and the code will both compile and do what you expect (i.e.,
not maintain values from call to call).

You'll also want to print things *after* you set the content type and
status, not before.

(darren)

--
The biggest difference between time and space is that you can't
reuse time.
-- Merrick Furst



Re: variables not changing with modperl??

2002-08-13 Thread Paul Simon
Hi darren
Did you try starting apache with "httpd -X". It spawns only one process and that helps keep things inorder, as far as variable values. You can try trouble shooting with that.
darren chamberlain <[EMAIL PROTECTED]>wrote:
* Michael Drons <[EMAIL PROTECTED]>[2002-08-13 01:55]: Thanks for the link. I actually don't use functions. Everything is mostly in MAIN. Here is a snip of code: #!/usr/bin/perl -wT use strict; print ""; my $r = Apache-request; $r-content_type("text/html"); $r-status(200); my $auth_type = $r-auth_type; $cookie=$auth_type-key; ($user,$hash)=split(/:/,$cookie); read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'}); my @pairs = split(//, $buffer); foreach my $pair (@pairs) {  } What I am doing wrong? Everytime the script runs the values of the variables coming in change. Should I use the delete function and delete all of the variables at the end of the script? @pairs is what should change, but sometimes does not. I have tried to add a undef @pairs before the split, but no luck.Are you sure that this is the code that is running? It doesn't compile:$ perl#!/usr/bin/perl -wTuse strict;print "";my $r = Apache-request;$r-content_type("text/html");$r-status(200);my $auth_type = $r-auth_type;$cookie=$auth_type-key;($user,$hash)=split(/:/,$cookie);read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});my @pairs = split(//, $buffer);foreach my $pair (@pairs) { }Global symbol "$cookie" requires explicit package name at - line 7.Global symbol "$user" requires explicit package name at - line 8.Global symbol "$hash" requires explicit package name at - line 8.Global symbol "$cookie" requires explicit package name at - line 8.Execution of - aborted due to compilation errorsMake those global symbols ($cookie, $user, and $hash) lexical (declarewith my) and the code will both compile and do what you expect (i.e.,not maintain values from call to call).You'll also want to print things *after* you set the content type andstatus, not before.(darren)--The biggest difference between time and space is that you can'treuse time.-- Merrick FurstDo You Yahoo!?
HotJobs, a Yahoo! service - Search Thousands of New Jobs

Re: variables not changing with modperl??

2002-08-13 Thread Perrin Harkins

darren chamberlain wrote:
 Make those global symbols ($cookie, $user, and $hash) lexical (declare
 with my) and the code will both compile and do what you expect (i.e.,
 not maintain values from call to call).

That's what I was thinking too.  Also, it's really not a good idea to do 
your own parsing of the input and cookies.  You should use one of the 
CGI modules or Apache::Request and Apache::Cookie for this.  Writing 
your own routine for this is just asking for security problems and bugs.

- Perrin





Re: variables not changing with modperl??

2002-08-13 Thread Michael Drons

Sorry,  There is a my in front of the ($cookie,$user)
code.  I am confused about your second statement about
parsing the input.  What should I be doing?  Do you
mean I should use $r-read($content,
$r-header_in('Content-length'))? to read in the
variables?  

I use the AuthCookie modules to set the cookies and to
authenicate.

Mike


--- Perrin Harkins [EMAIL PROTECTED] wrote:
 darren chamberlain wrote:
  Make those global symbols ($cookie, $user, and
 $hash) lexical (declare
  with my) and the code will both compile and do
 what you expect (i.e.,
  not maintain values from call to call).
 
 That's what I was thinking too.  Also, it's really
 not a good idea to do 
 your own parsing of the input and cookies.  You
 should use one of the 
 CGI modules or Apache::Request and Apache::Cookie
 for this.  Writing 
 your own routine for this is just asking for
 security problems and bugs.
 
 - Perrin
 
 


__
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



Re: variables not changing with modperl??

2002-08-13 Thread Ken Y. Clark

On Tue, 13 Aug 2002, Michael Drons wrote:

 Date: Tue, 13 Aug 2002 07:46:16 -0700 (PDT)
 From: Michael Drons [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: Perrin Harkins [EMAIL PROTECTED],
  darren chamberlain [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: variables not changing with modperl??

 Sorry,  There is a my in front of the ($cookie,$user)
 code.  I am confused about your second statement about
 parsing the input.  What should I be doing?  Do you
 mean I should use $r-read($content,
 $r-header_in('Content-length'))? to read in the
 variables?

Michael,

In one of your posts, you included the following code:

#!/usr/bin/perl -wT
use strict;
print body;
my $r = Apache-request;
$r-content_type(text/html);
$r-status(200);
my $auth_type = $r-auth_type;
$cookie=$auth_type-key;
($user,$hash)=split(/:/,$cookie);
read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
my @pairs = split(//, $buffer);
foreach my $pair (@pairs) {

}

There is no my in front of $cookie or $user variables.  If you are
lexically scoping them somewhere else in your script, please include
enough of an example for us to help you.

 I use the AuthCookie modules to set the cookies and to
 authenicate.

As for this and Perrin's comment about parsing on your own, the point
is that you've written a lot of code that has already been written and
debugged by a lot of really smart people.  There's no reason for you
to be reading STDIN and spliting and all that.  If you're using
mod_perl, then you really should do yourself a favor and read up on
Apache::Request and Apache::Cookie for doing all this stuff.  It's
much faster (it's written in c), safer (it's been debugged), easier
(just install the module), and standard (i.e., more maintainable).

Of course, some people say that the nice thing about standards is that
there are so many to choose from.  :)

ky




Re: variables not changing with modperl??

2002-08-13 Thread Perrin Harkins

Ken Y. Clark wrote:
 As for this and Perrin's comment about parsing on your own, the point
 is that you've written a lot of code that has already been written and
 debugged by a lot of really smart people.  There's no reason for you
 to be reading STDIN and spliting and all that.  If you're using
 mod_perl, then you really should do yourself a favor and read up on
 Apache::Request and Apache::Cookie for doing all this stuff.

Even if you are just using CGI, you shouldn't write your own parsing 
code like this.  Rather than try to explain why, I'll point you to this 
article on the subject:
http://perlmonks.org/index.pl?node_id=51012

- Perrin






Re: variables not changing with modperl??

2002-08-12 Thread Michael Drons

Thanks for the link.  I actually don't use functions. 
Everything is mostly in MAIN.  Here is a snip of code:

#!/usr/bin/perl -wT
use strict;
print body;
my $r = Apache-request;
$r-content_type(text/html);
$r-status(200);
my $auth_type = $r-auth_type;
$cookie=$auth_type-key;
($user,$hash)=split(/:/,$cookie);
read(STDIN, my $buffer, $ENV{'CONTENT_LENGTH'});
my @pairs = split(//, $buffer);
foreach my $pair (@pairs) {

}

What I am doing wrong?  Everytime the script runs the
values of the variables coming in change.  Should I
use the delete function and delete all of the
variables at the end of the script?  @pairs is what
should change, but sometimes does not.  I have tried
to add a undef @pairs before the split, but no luck.


Mike

--- Perrin Harkins [EMAIL PROTECTED] wrote:
 Michael Drons wrote:
  I am using Apache::Registry (Apache 1.3.26) I am
 see
  weird things happen with my scripts.  I have have
 use
  strict in all of the scripts and I use my() for
 all
  of my variables.  But I still have variables that
  contain data from previous loads.
 
 Sounds like the closure problem with subroutines in
 Apache::Registry. 
 Does you code have subroutines that refer to
 variables declared outside 
 of them?
 
  Everything I can find in docs says read the FAQ at
 
  http://perl.apache.org/faq/, which does not
 exists.
 
 Read this:

http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my___Scoped_Variable_in_Nested_Subroutines
 
 - Perrin
 


__
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com