mp1 to mp2: server info in startup.pl
Hi, I am trying to get server information (e.g. port) from within the startup.pl script. In mp2 I am doing this: --- use Apache2::ServerRec (); use Apache2::ServerUtil (); my $s = Apache2::ServerUtil->server(); warn "port = ",$s->port(),"\n"; output is: port = 0 In mp1 I am doing this: --- use Apache::Server; my $s = Apache->server; warn "port = ",$s->port(),"\n"; output is: port = 80 What am I doing wrong in mp2? Thanks, Ted
Re: mp1 to mp2: server info in startup.pl
In mp2 I am doing this: --- use Apache2::ServerRec (); use Apache2::ServerUtil (); my $s = Apache2::ServerUtil->server(); warn "port = ",$s->port(),"\n"; Try use Apache2::RequestUtil (); Apache2::RequestUtil->request()->get_server_port() Though I don't see why your method doesn't work. I'll give it a spin in a bit. -- END What doesn't kill us can only make us stronger. Nothing is impossible. Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198 Consultant / http://p6m7g8.net/Resume/ Senior Developer / Liquidity Services, Inc. http://www.liquidityservicesinc.com http://www.liquidation.com http://www.uksurplus.com http://www.govliquidation.com http://www.gowholesale.com
Re: mp1 to mp2: server info in startup.pl
Thanks for your response. I tried that, but got an error: [Mon Aug 22 14:43:52 2005] [error] Global $r object is not available. Set:\n\t PerlOptions +GlobalRequest\nin httpd.conf at /usr/local/apache2/conf/startup.pl line 82.\nCompilation failed in require at (eval 2) line 1.\n [Mon Aug 22 14:43:52 2005] [error] Can't load Perl file: /usr/local/apache2/conf /startup.pl for server (null):0, exiting... I also tried adding the PerlOptions values as indicated, but that didn't help. Philip M. Gollucci wrote: In mp2 I am doing this: --- use Apache2::ServerRec (); use Apache2::ServerUtil (); my $s = Apache2::ServerUtil->server(); warn "port = ",$s->port(),"\n"; Try use Apache2::RequestUtil (); Apache2::RequestUtil->request()->get_server_port() Though I don't see why your method doesn't work. I'll give it a spin in a bit.
Re: mp1 to mp2: server info in startup.pl
Philip M. Gollucci wrote: In mp2 I am doing this: --- use Apache2::ServerRec (); use Apache2::ServerUtil (); my $s = Apache2::ServerUtil->server(); warn "port = ",$s->port(),"\n"; Try use Apache2::RequestUtil (); Apache2::RequestUtil->request()->get_server_port() Though I don't see why your method doesn't work. I'll give it a spin in a bit. Okay, I'll verify that neither method works from startup.pl whether I pull it in via PerlRequire or PerlPostConfigRequire. I will say that the following handler gives me mixed Results: package TEST::Port; use strict; use warnings FATAL => 'all'; use Carp; use Apache2::RequestUtil (); use Apache2::ServerUtil (); use Apache2::Const -compile => qw (OK); sub handler { my $r = shift; $r->content_type('text/html'); my $s = $r->server(); my $port1 = $s->port(); my $port2 = $r->get_server_port(); my $port3 = Apache2::ServerUtil->server()->port(); $r->print("Ports: $port1, $port2, $port3 \n"); return Apache2::Const::OK; } Gives me: Ports: 0, 8000, 0 I checked in httpd/server/core.c:ap_get_server_port() via gdb and yes, it does return 8000. So that verifies #2 works. As far as I can tell 1, 3 don't come through this function.. but I can't for the life of me figure out where the hell they do go. Any ideas? I also can't see where $s->port() is tested in the test suite. Only $r->get_server_port is which works :) I would assume the end up calling the same function though. -- END What doesn't kill us can only make us stronger. Nothing is impossible. Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198 Consultant / http://p6m7g8.net/Resume/ Senior Developer / Liquidity Services, Inc. http://www.liquidityservicesinc.com http://www.liquidation.com http://www.uksurplus.com http://www.govliquidation.com http://www.gowholesale.com
Re: mp1 to mp2: server info in startup.pl
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Philip M. Gollucci wrote: >> In mp2 I am doing this: >> --- >> use Apache2::ServerRec (); >> use Apache2::ServerUtil (); >> my $s = Apache2::ServerUtil->server(); >> warn "port = ",$s->port(),"\n"; > > Try > use Apache2::RequestUtil (); > Apache2::RequestUtil->request()->get_server_port() > I would expect none of these solutions to work: 1. Solution: - Where from should perl know which port you are refering to / interested in or turn it the other way round what happens when you server listens to more than one port on more than one IP addresses? - ---8<- Listen 192.170.2.1:80 Listen 192.170.2.5:8000 - ---8<- I haven't read the HTTP-API docs of this function but in short this API doesn't make any sense at least it should return a List and not a Scalar. 2. Solution: - Where from should perl have a request in the startup-phase? The API in request-context makes sense because an request is really made to one port. > Though I don't see why your method doesn't work. I'll give it a spin in > a bit. > You want is retrieving configuration values which can be done using Apache2::Directive: startup.pl: - -8<- use Apache2::Directive; my $tree = Apache2::Directive::conftree(); my @ports = $tree->lookup('Listen'); foreach( @ports ) { print "The server listens to port: $_\n"; } - -8<- httpd.conf: - -8<- # # PerlPostConfigRequire conf/startup.pl - -8<- -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.0 (GNU/Linux) Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org iD8DBQFDDDRvkVPeOFLgZFIRAhIxAJ9htGeljs/zdhHPRmCW1X9m0gCrDACeJVcA TBm5467aUZbE2aRdXRK6wHg= =IQBZ -END PGP SIGNATURE-
Re: mp1 to mp2: server info in startup.pl
Tom Schindl wrote: I would expect none of these solutions to work: Don;t know if you read my reply to that with the handler example. 1. Solution: - Where from should perl know which port you are refering to / interested in or turn it the other way round what happens when you server listens to more than one port on more than one IP addresses? - ---8<- Listen 192.170.2.1:80 Listen 192.170.2.5:8000 - ---8<- This is a good point. I haven't read the HTTP-API docs of this function but in short this API doesn't make any sense at least it should return a List and not a Scalar. I believe the API is copied from httpd's ap [ap_get_server_port()] via XS glue. 2. Solution: - Where from should perl have a request in the startup-phase? The API in request-context makes sense because an request is really made to one port. Agreed. Which is why my _1st_ response made no sense in hind sight. You want is retrieving configuration values which can be done using Apache2::Directive: I had thought about that, I knew it would work, but I discounted from some reason -- can't remember why though. -- END What doesn't kill us can only make us stronger. Nothing is impossible. Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198 Consultant / http://p6m7g8.net/Resume/ Senior Developer / Liquidity Services, Inc. http://www.liquidityservicesinc.com http://www.liquidation.com http://www.uksurplus.com http://www.govliquidation.com http://www.gowholesale.com