mod_perl 2.0 globals question

2004-05-27 Thread Nathanial P. Hendler

I'm not sure if this is a style or function question.  I'd like to have a
module called Debug.pm that has a variable in it that if set to '1' by
anything (main script, or other modules) will print debug messages.

Reading the Orielly "Practical mod_perl" I thought it was clear what I
needed to do, but I am finding it difficult.  The following works as one
file, but when I break the Debug part into its own file, the value of $D
just increments with every re-load...

#!/usr/local/bin/perl

use strict;
use warnings;
use CGI qw(:standard);
use Debug;

print header();

Debug::report('I should not see this line');
$Debug::D++;
Debug::report('I should see this line');
$Debug::D++;
Debug::report('This one too');

package Debug;
use strict;
use warnings;

use vars qw($D);
$D = 0;

sub report {
my $string = shift;

print "DEBUG ($D): $string\n" if $D;
}

1;


Can anyone explain to me why I can't have a global variable when I put
Debug into its own file?

Can anyone tell me how to accomplish what I'm after?

Thanks,
Nathanial Hendler
Tucson, AZ USA
http://retards.org/


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: mod_perl 2.0 globals question

2004-05-27 Thread Tom Schindl
Nathanial P. Hendler wrote:
I'm not sure if this is a style or function question.  I'd like to have a
module called Debug.pm that has a variable in it that if set to '1' by
anything (main script, or other modules) will print debug messages.
Reading the Orielly "Practical mod_perl" I thought it was clear what I
needed to do, but I am finding it difficult.  The following works as one
file, but when I break the Debug part into its own file, the value of $D
just increments with every re-load...
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
use Debug;
print header();
Debug::report('I should not see this line');
$Debug::D++;
Debug::report('I should see this line');
$Debug::D++;
Debug::report('This one too');
package Debug;
use strict;
use warnings;
use vars qw($D);
$D = 0;
sub report {
my $string = shift;
print "DEBUG ($D): $string\n" if $D;
}
1;
Can anyone explain to me why I can't have a global variable when I put
Debug into its own file?
Well that's mod_perl. It will compile your script only once perl 
forked-process|thread (which means it also loads your Debug.pm only 
once) hence all global variables hold their value.

This means the following:
* you should see:
  ---8<---
  I should see this line
  This one too
  ---8<---
  when the request is served by new forked/thread process which has not
  already loaded your YourModule.pm.
* you should see :
  ---8<---
  I should not see this line
  I should see this line
  This one too
  ---8<---
  on any next request servered by *exactly this* apache-child.
What you could do:
* reset $Debug::D directly before print header()
  e.g. Debug::reset()
* make an object out of debug:
  e.g. $debug = new Debug(), $debug->increment_counter()
* use mod_perls logging capabilities.

Can anyone tell me how to accomplish what I'm after?
Do you want to increase/decrease verbosity or why are you incrementing 
$D

Tom
Thanks,
Nathanial Hendler
Tucson, AZ USA
http://retards.org/


--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: mod_perl 2.0 globals question

2004-05-27 Thread Tom Schindl
Nathanial P. Hendler wrote:
I'm not sure if this is a style or function question.  I'd like to have a
module called Debug.pm that has a variable in it that if set to '1' by
anything (main script, or other modules) will print debug messages.
Reading the Orielly "Practical mod_perl" I thought it was clear what I
needed to do, but I am finding it difficult.  The following works as one
file, but when I break the Debug part into its own file, the value of $D
perl runs through the whole code and $D gets set to 0:
* when module is loaded
* when perl runs through the compiled code (at the end of every request)
The var does not get reset at the start of request but at the end of it 
:-)))

just increments with every re-load...
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
use Debug;
print header();
Debug::report('I should not see this line');
$Debug::D++;
Debug::report('I should see this line');
$Debug::D++;
Debug::report('This one too');
package Debug;
use strict;
use warnings;
use vars qw($D);
$D = 0;
sub report {
my $string = shift;
print "DEBUG ($D): $string\n" if $D;
}
1;
Can anyone explain to me why I can't have a global variable when I put
Debug into its own file?
Can anyone tell me how to accomplish what I'm after?
Thanks,
Nathanial Hendler
Tucson, AZ USA
http://retards.org/


--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp2] migrating Apache::Cookie from mp1

2004-05-27 Thread Boris Zentner

Hi,

Am Donnerstag 27 Mai 2004 11:39 schrieb Casey Songer:
> I've been running site using mod_perl and HTML::Mason for 3-4 years with
> few problems.  I recently am being asked to move everything to a new box
> that has Apache2 running on it (with mp2).  I was able to install and
> get everything running for a site with no sessions and everything seems
> to be working fine.  For another site, I was using Apache::Cookie for
> session management.  I tried using the same code as for with mp1 with
> just changing  the parse call to fetch (see code below).  The cookies
> aren't working.  As far as I can tell, cookie->new() is failing in
> Apache/Session/Generate/MD5.pm in the validate() function.  I guess my
> question is first of all, am I going about this the right way?  (It's
> been a while since I set up the original mp1 cookies code).  Are people
> using the new Apache::Cookie (libapreq2)?  The documentation I've been
> able to find for it is pretty sparse so far.  Can somebody point me to
> some source code or better documentation than what I have found so far?
>
> Here are the versions of stuff I am using:
> Apache: 2.0.49
> mod_perl: 1.99_13
> libapreq2: 2.02_02
>

Use a more recent version of libapreq2 since at least up to libapreq2 2.02_02 
the cookies expire way to early.

It is fixed in cvs. Or here a version I used some time ago and build errors 
fixed ;-) . http://eg.2bz.de/httpd-apreq-2-19042004.tar.gz

Your code looks fine, but perhaps you use a wrong $r? Try $r->env but this is 
just a guess.

> my $cookie = Apache::Cookie->new($r, ...
my $cookie = Apache::Cookie->new($r->env, ...

>my $cookies = Apache::Cookie->fetch($r);
my $cookies = Apache::Cookie->fetch($r->env);

-- 
Boris


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: mod_perl 2.0 globals question

2004-05-27 Thread Tom Schindl
Nathanial P. Hendler wrote:
I'm not sure if this is a style or function question.  I'd like to have a
module called Debug.pm that has a variable in it that if set to '1' by
anything (main script, or other modules) will print debug messages.
Reading the Orielly "Practical mod_perl" I thought it was clear what I
needed to do, but I am finding it difficult.  The following works as one
file, but when I break the Debug part into its own file, the value of $D
perl runs through the whole code and $D gets set to 0:
* when module is loaded
* when perl runs through the compiled code (at the end of every request)
The var does not get reset at the start of request but at the end of it 
:-)))

just increments with every re-load...
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
use Debug;
print header();
Debug::report('I should not see this line');
$Debug::D++;
Debug::report('I should see this line');
$Debug::D++;
Debug::report('This one too');
package Debug;
use strict;
use warnings;
use vars qw($D);
$D = 0;
sub report {
my $string = shift;
print "DEBUG ($D): $string\n" if $D;
}
1;
Can anyone explain to me why I can't have a global variable when I put
Debug into its own file?
Can anyone tell me how to accomplish what I'm after?
Thanks,
Nathanial Hendler
Tucson, AZ USA
http://retards.org/


--
b e s t s o l u t i o n . a tEDV Systemhaus GmbH

tom schindlleiter softwareentwicklung   mobile  ++43 664 3145958

eduard-bodem-gasse 8/3A-6020 innsbruck  fax  ++43 512 935833
http://www.bestsolution.at  phone++43 512 935834
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


mod_perl not able to run some pl files.

2004-05-27 Thread Bheema Rao Merugu, BSC, Ambattur, Chennai



Hi,
 
 
I am getting the 
below error message in the error_log file. but I had the CGI.pm in the path 
/usr/local/apache/lib/perl5/5.8.3 
it's working in the 
other box where i have installed the perl in /usr/local path there are 
noproblems if i compiled the perl in default installation path and 
running.
but i am getting the 
problem when i compiled in a different location like 
/usr/local/apache.
 
[Thu May 27 18:38:43 2004] [error] Can't locate 
CGI.pm in @INC (@INC contains: 
/usr/local/apache/lib/perl5/5.8.3/aix-thread-multi 
/usr/local/apache/lib/perl5/5.8.3 
/usr/local/apache/lib/perl5/site_perl/5.8.3/aix-thread-multi 
/usr/local/apache/lib/perl5/site_perl/5.8.3 
/usr/local/apache/lib/perl5/5.8.3/aix-thread-multi 
/usr/local/apache/lib/perl5/5.8.3 
/usr/local/apache/lib/perl5/site_perl/5.8.3/aix-thread-multi 
/usr/local/apache/lib/perl5/site_perl/5.8.3 
/usr/local/apache/lib/perl5/site_perl . /usr/local/apache/ 
/usr/local/apache/lib/perl) at /export/home/perl/test.pl line 10.BEGIN failed--compilation 
aborted at /export/home/perl/test.pl line 
10.
 
Thanks,

Bheema



Re: mod_perl not able to run some pl files.

2004-05-27 Thread Brian Reichert
On Thu, May 27, 2004 at 07:45:49PM +0530, Bheema Rao Merugu, BSC, Ambattur, Chennai 
wrote:
> Hi,
>  
>  
> I am getting the below error message in the error_log file. but I had
> the CGI.pm in the path /usr/local/apache/lib/perl5/5.8.3 

When you say you 'had' CGI.pm in that path, do you mean that you
used that perl installation to make/install the module?

Or did you merely copy it in?  If the latter, make sure that you
have permissions on the file set properly.

> Thanks,
> Bheema

-- 
Brian Reichert  <[EMAIL PROTECTED]>
37 Crystal Ave. #303Daytime number: (603) 434-6842
Derry NH 03038-1713 USA BSD admin/developer at large

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: mod_perl 2.0 globals question

2004-05-27 Thread Nathanial P. Hendler
On Thu, 27 May 2004, Tom Schindl wrote:

> Nathanial P. Hendler wrote:
> > I'm not sure if this is a style or function question.  I'd like to have a
> > module called Debug.pm that has a variable in it that if set to '1' by
> > anything (main script, or other modules) will print debug messages.
> >
> > Reading the Orielly "Practical mod_perl" I thought it was clear what I
> > needed to do, but I am finding it difficult.  The following works as one
> > file, but when I break the Debug part into its own file, the value of $D
> > just increments with every re-load...
> >
> > #!/usr/local/bin/perl
> >
> > use strict;
> > use warnings;
> > use CGI qw(:standard);
> > use Debug;
> >
> > print header();
> >
> > Debug::report('I should not see this line');
> > $Debug::D++;
> > Debug::report('I should see this line');
> > $Debug::D++;
> > Debug::report('This one too');
> >
> > package Debug;
> > use strict;
> > use warnings;
> >
> > use vars qw($D);
> > $D = 0;
> >
> > sub report {
> > my $string = shift;
> >
> > print "DEBUG ($D): $string\n" if $D;
> > }
> >
> > 1;
> >
> >
> > Can anyone explain to me why I can't have a global variable when I put
> > Debug into its own file?
> >
>
> Well that's mod_perl. It will compile your script only once perl
> forked-process|thread (which means it also loads your Debug.pm only
> once) hence all global variables hold their value.
>
> This means the following:
> * you should see:
>---8<---
>I should see this line
>This one too
>---8<---
>when the request is served by new forked/thread process which has not
>already loaded your YourModule.pm.
> * you should see :
>---8<---
>I should not see this line
>I should see this line
>This one too
>---8<---
>on any next request servered by *exactly this* apache-child.
>
> What you could do:
> * reset $Debug::D directly before print header()
>e.g. Debug::reset()
> * make an object out of debug:
>e.g. $debug = new Debug(), $debug->increment_counter()
> * use mod_perls logging capabilities.

Ok, thanks.  The reason I haven't just made it an object is that I have
several modules, and I'd like them all to be able to call Debug::report()
and if the debug value ($D) is set, then it works, without having to pass
the debug object to every module.

I guess I just don't quite know how to do that.  Is there a way to have a
module run anycode any time another perl module/script uses it?

  use Debug;

would executed insided Debug.pm

 IM_BEING_USED {
 $D = 0;
 }

> Do you want to increase/decrease verbosity or why are you incrementing
> $D

So that a module can do `$D++; blah blah; $D--;` and it won't trounce
another module's initiation to turn on debuging.

Thanks for your help.

Nathan


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: mod_perl 2.0 globals question

2004-05-27 Thread Perrin Harkins
On Thu, 2004-05-27 at 13:08, Nathanial P. Hendler wrote:
> I guess I just don't quite know how to do that.  Is there a way to have a
> module run anycode any time another perl module/script uses it?
> 
>   use Debug;
> 
> would executed insided Debug.pm
> 
>  IM_BEING_USED {
>  $D = 0;
>  }

There is.  When you do a "use Debug" it looks for a sub called
Debug::import and runs it if one is found.  However, the use statement
happens only once, at compile time, not on every request.

If what you want is a flag that you can set which lasts only for the
length of a request, do it like this:

(Assuming that $r is the request object)
$r->pnotes('debug') = 1;

The pnotes structure is like a hash that gets cleared after every
request.

Ultimately, I would recommend that you just move to using Log::Log4Perl
instead.  It has tons of flexibility in how you set debug levels.

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



[mp2] $dbh and config values methods

2004-05-27 Thread Nathanial P. Hendler

Ok, so I'm convinced that I should be using Log::Log4Perl.  I'm using
ModPerl::Registry and was wondering if people could share their approaches
to configuration variables and database handlers under mp2.

I'd like to have a config module, that holds things like:

  $document_root= '/var/www/html';
  $images_base_path = $document_root . '/images';
  $images_base_url  = '/images';

  %phrases = ( red=>'This is red', blue=>'this is blue' );

But I can also think of reasons to have subroutines as well.  The module
would need to be available to all of the used modules, and I'd rather not
have to pass around a handle.  It also seems like it'd be nice if the
values were re-written, that it would only last for that session, but that
the change would be visible to all modules.

How do you guys deal with that?

What about a (or several) $dbh handle?  I'm going to have SQL queries in
all of my modules.  Do they all have to create their own $dbh?  Is there a
well understood approach to this that I'm not finding on the interweb?

Thanks again for all the help, I just seem to have a hard time building
complex perl systems the same way I used to under mod_perl 2.0, and need a
little experience and wisdom to make sure I head in mostly the right
direction.

Nathanial Hendler
Tucson, AZ USA
http://retards.org/


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: [mp2] $dbh and config values methods

2004-05-27 Thread Perrin Harkins
On Thu, 2004-05-27 at 14:13, Nathanial P. Hendler wrote:
> I'd like to have a config module, that holds things like:
> 
>   $document_root= '/var/www/html';
>   $images_base_path = $document_root . '/images';
>   $images_base_url  = '/images';
> 
>   %phrases = ( red=>'This is red', blue=>'this is blue' );
> 
> But I can also think of reasons to have subroutines as well.  The module
> would need to be available to all of the used modules, and I'd rather not
> have to pass around a handle.  It also seems like it'd be nice if the
> values were re-written, that it would only last for that session, but that
> the change would be visible to all modules.
> 
> How do you guys deal with that?

Well, first I would drop the crazy stuff about subroutines and changing
values in mid-flight.  That's not config and it belongs somewhere else.

There's a section on this in the guide:
http://perl.apache.org/docs/1.0/guide/porting.html#Configuration_Files__Writing__Dynamically_Updating_and_Reloading

I typically use one of the config file modules on CPAN and a simple
singleton pattern.  You could use Class::Singleton, or roll your own.

> What about a (or several) $dbh handle?  I'm going to have SQL queries in
> all of my modules.  Do they all have to create their own $dbh?  Is there a
> well understood approach to this that I'm not finding on the interweb?

It's been discussed here many times.  You either just connect in each
one, letting Apache::DBI handle the persistence, or you use a singleton
approach of some kind.  Check the mailing list archives for more.

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Apache/mod_perl/mysql - threads at startup

2004-05-27 Thread Mike Blazer
Hello, guys!
I use this configuration for quite a while and under a hard traffic:
Apache 1.3.29
mod_perl 1.29
mysql 4.0.3 (a rather old one)

for sometime I have this minor problem - each time I restart servers
there are few failures right after the restart. It's always "Lost
connection" error. As it's a hits counter I can live with it. After the
startup this problem never appears again.
But today I finally decided to explore what happens. Here is from my log
right immediatelly after restart:

(n) is child's pid, thread is $thread_id = $dbh->{mysql_thread_id}

[Thu May 27 08:10:33 2004] [error] reinit (11154) thread:133
[Thu May 27 08:10:33 2004] [error] reinit (11155) thread:133
[Thu May 27 08:10:33 2004] [error] reinit (11162) thread:133
[Thu May 27 08:10:33 2004] [error] reinit (11156) thread:134
[Thu May 27 08:10:33 2004] [error] reinit (11166) thread:136
[Thu May 27 08:10:33 2004] [error] ListTables: Lost connection to MySQL
server d
uring query
 at /host/counter/lib/Counter/ShowCounter.pm line 204

[Thu May 27 08:10:33 2004] [error] reinit (11168) thread:137
[Thu May 27 08:10:33 2004] [error] reinit (11167) thread:142
[Thu May 27 08:10:33 2004] [error] reinit (11159) thread:135
[Thu May 27 08:10:33 2004] [error] reinit (11158) thread:139
[Thu May 27 08:10:33 2004] [error] reinit (11157) thread:140
[Thu May 27 08:10:33 2004] [error] reinit (11160) thread:144
[Thu May 27 08:10:33 2004] [error] reinit (11165) thread:146

[Thu May 27 08:10:33 2004] [error] SQL execute error: SELECT VERSION()
Lost connection to MySQL server during query
 at /host/counter/lib/SQL/BuilderExt.pm line 147

[Thu May 27 08:10:33 2004] [error] server_version: could not determine
version
 at /host/counter/lib/SQL/BuilderExt.pm line 147

See, in the very beginning - 3 child processes started and connected to
the same mysql thread_id

None of my processes ever disconnects, they all use Apache:DBI and
everything is checked to be correct.
Seems like it's mysql error in dispatching threads?
I scanned mysql changelog - nothing that would look like this was fixed
up to the current version.

I tried all kinds of adjusting from
StartServers=> 15,
MinSpareServers => 5,
MaxSpareServers => 50,

to
StartServers=> 0,
MinSpareServers => 0,
MaxSpareServers => 50,

But at least 2 childs always connect to the same thread.

Any ideas?

Thanks!
-- 
==
Mike Blazer
[EMAIL PROTECTED]
==

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: Apache/mod_perl/mysql - threads at startup

2004-05-27 Thread Perrin Harkins
On Thu, 2004-05-27 at 15:20, Mike Blazer wrote:
> See, in the very beginning - 3 child processes started and connected to
> the same mysql thread_id
> 
> None of my processes ever disconnects, they all use Apache:DBI and
> everything is checked to be correct.
> Seems like it's mysql error in dispatching threads?

Usually it's something opening a database connection before apache
forks.  How about showing us the parts of your startup code that deal
with database connections?

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



passing data between connection and http filters

2004-05-27 Thread Eric J. Hansen
I have an application that uses mod_proxy (as a reverse proxy) to fetch content
from a back-end server.  My application needs to do some manipulation of both
the request headers and the response body.  Given that mod_proxy circumvents
most of mod_perl's handler phases, I'm having to use filters to do what I need
to do.

To manipulate the request headers, I'm using Stas' HTTPHeadersFixup module (i.e.,
I set Accept-Encoding: none, etc.)  Then I'm using a HTTP output filter to
analyze & modify the actual content as its being sent back to the browser.

The question I have is how to pass data between the input connection filter
and the output http filter.  For example, I'd like to set a yes/no flag, or even
a hash reference, and then retrieve it from the output filter. Ordinarily, I would
happily use notes/pnotes to do this, but since connection filters don't have
access to the $r object, this doesn't fly.  Any ideas for doing this conveniently,
short of using an external memory/db cache?

thanks
Eric


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



[ANNOUNCE] HTML::GenerateUtil 1.02

2004-05-27 Thread Robert Mueller
I thought some people on this list might find this useful.

http://search.cpan.org/~robm/HTML-GenerateUtil-1.02/

I think the "Context" section probably gives the best overview.

---

When  creating a web application in perl, you've got a couple of main
choices  on  how  to  actually generate the HTML that gets output:

  * Programatically generating the HTML in perl
  * Using  some  template  system for the HTML and inserting the data
calculated in perl as appropriate

Your   actual   application,  experience  and  environment  will
generally determine which is the best way to.

If  you  go  the programatic route, then you generally need some way of
generating the actual HTML output in perl. Again, there's generally a
couple of ways of doing this.

  * Just joining together text strings in perl as appropriate.
Eg. $link = "$text";
  * Or using some function module like CGI
Eg. $line = a({ href => $ref }, $text);
  * More complex object systems like HTML::Table

The  first  seems  easy,  but  it  gets  harder when you have to
manually  escape each string to avoid placing special HTML chars (eg <,
etc) in strings like $text above.

With  the  CGI, most of this is automatically taken care of, and most
strings  are automatically escaped to replace special HTML chars with
their entity equivalents.

While  this is nice, CGI is written in pure perl, and can end up being
a  bit slow, especially if you already have a fast system that
generates  pages  very  heavy  in  tags  (eg lots of table elements,
links, etc)

That's  where this module comes it. It provides functions useful for
escaping html and generating HTML tags, but it's all written in XS to
be
very fast. It's also fully UTF-8 aware.

---

Comments and suggestions welcome.

Rob

--

[EMAIL PROTECTED]

Sign up at http://fastmail.fm for fast, ad free, IMAP accessible email


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: passing data between connection and http filters

2004-05-27 Thread Stas Bekman
Eric J. Hansen wrote:
I have an application that uses mod_proxy (as a reverse proxy) to fetch content
from a back-end server.  My application needs to do some manipulation of both
the request headers and the response body.  Given that mod_proxy circumvents
most of mod_perl's handler phases, I'm having to use filters to do what I need
to do.
To manipulate the request headers, I'm using Stas' HTTPHeadersFixup module (i.e.,
I set Accept-Encoding: none, etc.)  Then I'm using a HTTP output filter to
analyze & modify the actual content as its being sent back to the browser.
The question I have is how to pass data between the input connection filter
and the output http filter.  For example, I'd like to set a yes/no flag, or even
a hash reference, and then retrieve it from the output filter. Ordinarily, I would
happily use notes/pnotes to do this, but since connection filters don't have
access to the $r object, this doesn't fly.  Any ideas for doing this conveniently,
short of using an external memory/db cache?
Yes, but you have connection notes, which work exactly like request notes but 
you call them on the connection object.
http://perl.apache.org/docs/2.0/api/Apache/Connection.html#C_notes_
The only problem you have with that is the need to know when to reset those 
notes, since with KeepAlive you will have more than one request coming over 
the same connection. It's a bit tricky, but it's explained here:
http://perl.apache.org/docs/2.0/user/handlers/filters.html#Connection_Filters_over_KeepAlive_Connections

Apache::Filter::HTTPHeadersFixup uses this exact communication technique that 
you are talking about.

--
__
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
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Apache/mod_perl/mysql - threads at startup

2004-05-27 Thread Mike Blazer
Thanks, Perrin, I'm sure you're right just don't see where this happens.

It's hard to extract the part of the code because my configs look wild
:)
One sh script starts/stops/restarts 3 servers with 1 config for proxy
and 1 config full of  sections - for two back-end servers.
Yes, I do call mysql from  section of conf-file.
One "thread" of this execution looks like

  require "$counter_root/startup-image.pl";
inside this file:
@Counter::INI::DBopendata = (
  base => 'ranks',
  host => "localhost",
  port => 3306,
  "username" => "",
  "password" => "",
);

...

# this is because I use the same startup-image.pl for standalone scripts
# with $no_GATEWAY_INTERFACE = 1;

require DBI;

unless ($no_GATEWAY_INTERFACE) {
  # Apache::DBI should be before DBI but after Apache::Status
  require Apache;
  require Apache::Status;
  require Apache::DBI;

  # here's a workaround to override DBI methods with Apache::DBI ones
  {
  package DBI;
  $connect_via = "Apache::DBI::connect";
  }

   lots more
}

then back to conf:

  my $db = MySQL::Tools->dbopen(@Counter::INI::DBopendata,
connect_method => "connect") or die $DBI::errstr;
print "image startup thread:".$db->dbh->{mysql_thread_id}."  
".scalar($db->dbh)."\n";

  # this is just an object-oriented interface to SQL language
  my $res = $db->select(
 Tables   => Counter::Folders->table_name,
 Columns  => "ICON",
 DISTINCT => 1,
 SQL_CACHE => 1,
  ) or die "reading counter images: ".MySQL::Tools->errstr;

  ref($res) && @$res or die "reading counter images: no images found\n";

  ...stuff...

  $db->dbclose;
  undef $db;

I'm calling this with connect_method => "connect" and really, I see this
result of the upper print:
image startup thread:717   DBI::db=HASH(0x8746500)

- means I really use DBI and dbclose is just a simple $dbh->disconnect
in this case. And I really don't see thread 717 any more

Actually there should've been a 2nd line (like I saw while printed to
file, I won't change thread id's here)
image startup thread:718   DBI::db=HASH(0x8746500)

because of the 2nd pass. Dunno, may be there is some problem with this
2nd pass... I don't actually know why it happens. But it's still DBI and
disconnects as DBI::db handler should disconnect.

OK, and after that the whole stuff starts, few different PerlHandler
modules that use the same dbh like this

sub handler {
...

$Counter::db and $Counter::db->reconnect;

unless ($Counter::db) {
  $Counter::db ||= MySQL::Tools->dbopen( @Counter::INI::DBopendata )
 or croak MySQL::Tools->errstr;
}

MySQL::Tools->dbopen returns $db and $db->dbh is DBI::db object (or
Apache::DBI::db in case it overrides DBI)

dbopen() finishes with 

  $self->reconnect or return;

  $self;
}

and reconnect() actually opens the connection:

sub reconnect {
 my $self = shift;
  my $old_dbh = $self->{dbh} ? "$self->{dbh}" : "";
  my $old_thr = $self->{dbh} ? ($self->{dbh}->{mysql_thread_id} || 0) :
0;

  $self->{"dbh"} and $self->{"dbh"}->disconnect;
  $self->{"dbh"} = DBI->connect(
sprintf("dbi:%s:database=%s;host=%s;port=%s",
$self->{"driver"}, $self->{"name"}, $self->{"host"}, $self->{"port"}),
$self->{"username"}, $self->{"password"}, {
AutoCommit => 1, # 0 makes error in mysql
PrintError => 0,
RaiseError => 0,
($self->{"connect_method"} ? (
dbi_connect_method => $self->{"connect_method"}
) : ()),
  }) or return;

  my $new_thr = $self->{dbh} ? ($self->{dbh}->{mysql_thread_id} || 0) :
0;

  !$old_dbh || $old_dbh eq "$self->{dbh}" or
 warn "reconnect: reconnected successfully\n";

  if (Apache->request && $old_thr != $new_thr) {
warn "reinit ($$) thread new: $new_thr   old: $old_thr  
$self->{dbh}\n";
  }

  ... reading tables with column properties ...

  $self;
}

I've just made more clear test print and the last 'warn' prints much
like I sent before but now it shows how wrong mysql thread (719 - same
for 5 server childs) is being replaced with the new threads:
old: 0 means first connection for this child, no previous thread

[Thu May 27 16:00:23 2004] [error] reinit (13339) thread new: 719   old:
0   Apache::DBI::db=HASH(0x8389fa4)
[Thu May 27 16:00:23 2004] [error] reinit (13341) thread new: 719   old:
0   Apache::DBI::db=HASH(0x8389fa4)
[Thu May 27 16:00:23 2004] [error] reinit (13340) thread new: 719   old:
0   Apache::DBI::db=HASH(0x8389fa4)
[Thu May 27 16:00:23 2004] [error] reinit (13342) thread new: 719   old:
0   Apache::DBI::db=HASH(0x8389fa4)
[Thu May 27 16:00:23 2004] [error] reinit (13343) thread new: 719   old:
0   Apache::DBI::db=HASH(0x8389fa4)
[Thu May 27 16:00:23 2004] [error] SQL execute error: LISTFIELDS
counter_sitegroups
Lost connection to MySQL server during query
 at /host/counter/lib/Counter/Common.pm line 502
[Thu May 27 16:00:23 2004] [error] TablesProperties: Lost connection to
MySQL server during query
 at /host/counter/lib/Counter/Common.pm line 502

[Thu May 27 16:00:23 20

An advice

2004-05-27 Thread
Somebody told me that if i use the data type "bytea" for my images 
in postgresql it could be very heavy in the web, does mod_perl
have a good solution for that? 

Thanks


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



RE: mod_perl not able to run some pl files.

2004-05-27 Thread Bheema Rao Merugu, BSC, Ambattur, Chennai
Hi,

thank you for your resposne Brian,
Yes, I used the perl installed in that path. I have installed the perl
with make install and using the same perl.
I have not copied CGI.pm just like that in to the path. Its came with
the installation only.

Thnaks,
Bheema


-Original Message-
From: Brian Reichert [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 27, 2004 10:01 PM
To: Bheema Rao Merugu, BSC, Ambattur, Chennai
Cc: [EMAIL PROTECTED]; Stas Bekman
Subject: Re: mod_perl not able to run some pl files.


On Thu, May 27, 2004 at 07:45:49PM +0530, Bheema Rao Merugu, BSC,
Ambattur, Chennai wrote:
> Hi,
>  
>  
> I am getting the below error message in the error_log file. but I had
> the CGI.pm in the path /usr/local/apache/lib/perl5/5.8.3 

When you say you 'had' CGI.pm in that path, do you mean that you
used that perl installation to make/install the module?

Or did you merely copy it in?  If the latter, make sure that you
have permissions on the file set properly.

> Thanks,
> Bheema

-- 
Brian Reichert  <[EMAIL PROTECTED]>
37 Crystal Ave. #303Daytime number: (603) 434-6842
Derry NH 03038-1713 USA BSD admin/developer at large

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



[mp2 milestones] installment 1

2004-05-27 Thread Stas Bekman
Hi,
As we have mentioned several times on this list mod_perl 2.0 will be released
when a selected API will be reviewed, tested and documented and the release
todo file http://cvs.apache.org/viewcvs.cgi/modperl-2.0/todo/release gets emptied.
This is the first installment of getting to the final goal of releasing 2.0
and it requires your attention.
   
Here are the first 15 modules that have their API more or less frozen, tested
and documented. Make sure you read the man pages thoroughly, since once 2.0.0
is released we will not be able to change the existing API in the following
2.0.x releases, if the changes break backwards compatibility with 2.0.0
release. At the moment we can still change things, therefore please make sure
that you review the following man pages:
http://perl.apache.org/docs/2.0/api/APR/Base64.html
http://perl.apache.org/docs/2.0/api/APR/Brigade.html
http://perl.apache.org/docs/2.0/api/APR/Bucket.html
http://perl.apache.org/docs/2.0/api/APR/BucketAlloc.html
http://perl.apache.org/docs/2.0/api/APR/BucketType.html
http://perl.apache.org/docs/2.0/api/APR/Date.html
http://perl.apache.org/docs/2.0/api/APR/Error.html
http://perl.apache.org/docs/2.0/api/APR/IpSubnet.html
http://perl.apache.org/docs/2.0/api/APR/Pool.html
http://perl.apache.org/docs/2.0/api/APR/SockAddr.html
http://perl.apache.org/docs/2.0/api/APR/Socket.html
http://perl.apache.org/docs/2.0/api/APR/Table.html
http://perl.apache.org/docs/2.0/api/APR/ThreadMutex.html
http://perl.apache.org/docs/2.0/api/APR/URI.html
http://perl.apache.org/docs/2.0/api/APR/Util.html
Quite a few methods have changed since 1.99_14 release. You will need to use
the current mod_perl cvs
http://perl.apache.org/download/source.html#Development_mod_perl_2_0_Source_Distribution
in order to match the documentation if you try to code or port things. You can
refer to the Changes file to see what has changed since the last release:
http://cvs.apache.org/viewcvs.cgi/modperl-2.0/Changes
If you want to discuss a certain module or a function, please don't reply to
this email but start a separate thread using a relevant subject name. For example:
  [mp2] APR::Socket::recv issues
Contributions in the form of patches to the code, tests and documentations are
more than welcome. Here is how you can contribute:
If you wish to send documentation fixes and improvements please use the
modperl-docs repository as explained here:
http://perl.apache.org/download/docs.html
http://perl.apache.org/contribute/cvs_howto.html#Sending_Patches
If you wish to help us and write more tests, please send patches against the
current mod_perl cvs:
http://perl.apache.org/download/source.html#Development_mod_perl_2_0_Source_Distribution
Thank you.
   
I still have several issues with a few APR:: modules not listed above, but I'm
going to work on the Apache:: modules next. So the next installment will
include a batch of Apache:: API man pages to review.
--
__
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
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


RE: mod_perl not able to run some pl files.

2004-05-27 Thread Bheema Rao Merugu, BSC, Ambattur, Chennai
Hi,


Please find the CGI.pm version installed in my system

# perl -MCGI -e 'print "CGI.pm version $CGI::VERSION\n";'
CGI.pm version 3.01
even though its giving the error I think there is some configuration
issue with apache and mod_perl.

[Thu May 27 18:38:43 2004] [error] Can't locate CGI.pm in @INC (@INC
contains: /usr/local/apache/lib/perl5/5.8.3/aix-thread-multi
/usr/local/apache/lib/perl5/5.8.3
/usr/local/apache/lib/perl5/site_perl/5.8.3/aix-thread-multi
/usr/local/apache/lib/perl5/site_perl/5.8.3
/usr/local/apache/lib/perl5/5.8.3/aix-thread-multi
/usr/local/apache/lib/perl5/5.8.3
/usr/local/apache/lib/perl5/site_perl/5.8.3/aix-thread-multi
/usr/local/apache/lib/perl5/site_perl/5.8.3
/usr/local/apache/lib/perl5/site_perl . /usr/local/apache/
/usr/local/apache/lib/perl) at /export/home/perl/test.pl line 10.
BEGIN failed--compilation aborted at /export/home/perl/test.pl line 10.


Thanks,
Bheema.

-Original Message-
From: Brian Reichert [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 27, 2004 10:01 PM
To: Bheema Rao Merugu, BSC, Ambattur, Chennai
Cc: [EMAIL PROTECTED]; Stas Bekman
Subject: Re: mod_perl not able to run some pl files.


On Thu, May 27, 2004 at 07:45:49PM +0530, Bheema Rao Merugu, BSC,
Ambattur, Chennai wrote:
> Hi,
>  
>  
> I am getting the below error message in the error_log file. but I had
> the CGI.pm in the path /usr/local/apache/lib/perl5/5.8.3 

When you say you 'had' CGI.pm in that path, do you mean that you
used that perl installation to make/install the module?

Or did you merely copy it in?  If the latter, make sure that you
have permissions on the file set properly.

> Thanks,
> Bheema

-- 
Brian Reichert  <[EMAIL PROTECTED]>
37 Crystal Ave. #303Daytime number: (603) 434-6842
Derry NH 03038-1713 USA BSD admin/developer at large

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html



Re: [mp2] $dbh and config values methods

2004-05-27 Thread Tom Schindl
Nathanial P. Hendler wrote:
Ok, so I'm convinced that I should be using Log::Log4Perl.  I'm using
ModPerl::Registry and was wondering if people could share their approaches
to configuration variables and database handlers under mp2.
I'd like to have a config module, that holds things like:
  $document_root= '/var/www/html';
  $images_base_path = $document_root . '/images';
  $images_base_url  = '/images';
  %phrases = ( red=>'This is red', blue=>'this is blue' );
To read config-files you could use 
http://search.cpan.org/~wadg/Config-IniFiles-2.38/. When it comes to the 
point of creating an Configuration-Class (e.g. to represent things like 
above) its common to use Singleton-Pattern.

But I can also think of reasons to have subroutines as well.  The module
would need to be available to all of the used modules, and I'd rather not
have to pass around a handle.  It also seems like it'd be nice if the
values were re-written, that it would only last for that session, but that
the change would be visible to all modules.
How do you guys deal with that?
What about a (or several) $dbh handle?  I'm going to have SQL queries in
all of my modules.  Do they all have to create their own $dbh?  Is there a
well understood approach to this that I'm not finding on the interweb?
Thanks again for all the help, I just seem to have a hard time building
complex perl systems the same way I used to under mod_perl 2.0, and need a
little experience and wisdom to make sure I head in mostly the right
direction.
As Perrin already said Apache::DBI or once more a Singleton-Class 
providing the DBH, although I'd use Apache::DBI because it handles 
everthing for you.

Nathanial Hendler
Tucson, AZ USA
http://retards.org/


--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html