Cassi has asked for the wisdom of the Perl Monks concerning the following question:

Im creating a modperl2 script and I need to know wich ips are connected to the server, later alot of time trying to find a solution, alot of read about the api, with no sucess Im asking for help :) . Someone know how can I do it?
  • Comment on Trying to find open connections at apache2

Replies are listed 'Best First'.
Re: Trying to find open connections at apache2
by ides (Deacon) on Nov 12, 2006 at 17:05 UTC

    If you're talking about getting the IP address of the browser for the particular connection you are dealing with it is just:

    use Apache2::Connection; use Apcache2::RequestRec; my $client_ip = $r->connection->remote_addr;

    If you're wanting all of the IPs currently connected to all of your Apache children, then you are going to need to write a special handler that will log ( to a file or database ) when a connection comes in, and then remove it again during a Cleanup phase.

    Frank Wiles <frank@revsys.com>
    www.revsys.com

Re: Trying to find open connections at apache2
by CountZero (Bishop) on Nov 12, 2006 at 18:51 UTC
    Webserver "connections" are by their very nature short-lived. The web-client makes a request and the server answers this request. This normally takes perhaps a few seconds and then the "connection" disappears.

    If you have actived the status-module in your Apache-server, you can see which requests are being serviced and which IPs are linked to these requests.

    Apache2::RequestRec::connection gets you the connection record for this request and the Apache2::Connection::get_remote_host gets you the client's IP or host name.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      http://httpd.apache.org/docs/2.0/mod/mod_status.html This one can be a solution for me but I cant see how to access this information as the Apache2::Status show me things about the Embedded interpreter status, and aparently cannot return the current hosts and requests being processed Some idea? Thanks
        http://search.cpan.org/~mjh/Apache-Scoreboard-2.08/lib/Apache/Scoreboard.pm I continue making tests and I now I found this module from CPAN, wich is an API to the scoreboard for modperl2, didnt made the tests with it but probably is exactly what I was looking for.
Re: Trying to find open connections at apache2
by imp (Priest) on Nov 12, 2006 at 15:44 UTC
    I am not aware of a way to get this information from modperl.

    An external solution would be to use lsof, as demonstrated here

    Whether this is appropriate depends on the problem you are trying to solve.