docs::a...nection(3)
π NAME π
okay so this is docs::a...nection(3) from User Contributed Perl Documentation, and it's the main-character manual page for Apache2::Connection β the Perl API for Apache connection object. periodt. π
β¨ Synopsis β¨
bestie, here's the synopsis in all its code-block glory β every line is doing its own little slay, so don't skip a single one: πΈ
use Apache2::Connection ();
use Apache2::RequestRec ();
my $c = $r->connection;
my $c = $r->connection;
# is connection still open?
$status = $c->aborted;
# base server
$base_server = $c->base_server();
# needed for creating buckets/brigades
$ba = $c->bucket_alloc();
# client's socket
$socket = $c->client_socket;
# unique connection id
$id = $c->id();
# connection filters stack
$input_filters = $c->input_filters();
$output_filters = $c->output_filters();
# keep the connection alive?
$status = $c->keepalive();
# how many requests served over the current connection
$served = $c->keepalives();
# this connection's local and remote socket addresses
$local_sa = $c->local_addr();
$remote_sa = $c->remote_addr();
# local and remote hostnames
$local_host = $c->local_host();
$remote_host = $c->get_remote_host();
$remote_host = $c->remote_host();
# server and remote client's IP addresses
$local_ip = $c->local_ip();
$remote_ip = $c->remote_ip();
# connection level Apache notes
$notes = $c->notes();
# this connection's pool
$p = $c->pool();
No cap, that's the full synopsis stack: connection checks, base server, buckets/brigades setup, the client's socket, filters, keepalive, addresses, hostnames, IPs, notes, and the connection's pool. Every call is sitting right where the manual put it. β¨
πΈ Description πΈ
Apache2::RequestRec provides the Perl API for Apache connection record object. That's the description, short and iconic β no extra lore, just the facts. π
Part 1 stops here; more parts are pulling up, so stay tuned π
π
aborted
Is the connection still alive, or did it ghost us π
$status = $c->aborted();
- obj:
$c(anApache2::Connection object) - ret:
$status(boolean) βtrueif the connection has been aborted,falseif it's still open - since:
2.0.00
π¦ base_server
Which physical server did this connection come in on β the main server or a vhost?
$base_server = $c->base_server();
- obj:
$c(anApache2::Connection object) - ret:
$base_server(anApache2::Server object) - since:
2.0.00
π bucket_alloc
The bucket allocator you use for literally every bucket/brigade creation β¨
$ba = $c->bucket_alloc();
- obj:
$c(anApache2::Connection object) - ret:
$ba(anAPR::BucketAlloc object) - since:
2.0.00
You need this object forAPR::BucketandAPR::Brigademethods/functions. Non-negotiable, bestie π«Ά
π client_socket
Get β or set β the client socket
$socket = $c->client_socket;
$prev_socket = $c->client_socket($new_socket);
- obj:
$c(anApache2::Connection object) - opt arg1:
$new_socket(anAPR::Socket objectobject) β if you pass a new socket, it gets set - ret:
$socket(anAPR::Socket objectobject) β the current client socket. If the optional argument$new_socketwas passed, the previous socket object is returned instead - since:
2.0.00
π get_remote_host
Look up the client's DNS hostname or IP address π
$remote_host = $c->remote_host();
$remote_host = $c->remote_host($type);
$remote_host = $c->remote_host($type, $dir_config);
- obj:
$c(anApache2::Connection object) β the current connection - opt arg1:
$type(a:remotehost constant) β the type of lookup to perform:Apache2::Const::REMOTE_DOUBLE_REVβ will always force a DNS lookup, and also force a double reverse lookup, regardless of theHostnameLookupssetting. The result is the (double reverse checked) hostname, or undef if any of the lookups failApache2::Const::REMOTE_HOSTβ returns the hostname, orundefif the hostname lookup fails. It will force a DNS lookup according to theHostnameLookupssettingApache2::Const::REMOTE_NAMEβ returns the hostname, or the dotted quad if the hostname lookup fails. It will force a DNS lookup according to theHostnameLookupssettingApache2::Const::REMOTE_NOLOOKUPβ is likeApache2::Const::REMOTE_NAMEexcept that a DNS lookup is never forced- Default value is
Apache2::Const::REMOTE_NAME
- opt arg2:
$dir_config(anApache2::ConfVector object) β the directory config vector from the request. It's needed to find the container in which the directiveHostnameLookupsis set. To get one for the current request use$r->per_dir_config. By default,undefis passed, in which case it's the same as ifHostnameLookupswas set toOff - ret:
$remote_host(string/undef) β the remote hostname. If the configuration directive HostNameLookups is set to off, this returns the dotted decimal representation of the client's IP address instead. Might returnundefif the hostname is not known - since:
2.0.00
iykyk: the result of theget_remote_hostcall is cached in$c->remote_host. If the latter is set,get_remote_hostwill return that value immediately, w/o doing any checkups. Efficient queen π
π id
The ID of this connection β unique at any point in time
$id = $c->id();
- obj:
$c(anApache2::Connection object) - ret:
$id(integer) - since:
2.0.00
π§ input_filters
Get/set the first filter in a linked list of protocol level input filters:
$input_filters = $c->input_filters();
$prev_input_filters = $c->input_filters($new_input_filters);
- obj:
$c(anApache2::Connection object) - opt arg1:
$new_input_filtersβ set a new value - ret:
$input_filters(anApache2::Filter object) β the first filter in the connection input filters chain. If$new_input_filterswas passed, returns the previous value - since:
2.0.00
For an example see: Bucket Brigades-based Protocol Module π
π₯ keepalive
This method answers the big question: should the the connection be kept alive for another HTTP request after the current request is completed? π
$status = $c->keepalive();
$status = $c->keepalive($new_status);
- obj:
$c(anApache2::Connection object) - opt arg1:
$new_status(a:conn_keepalive constant) β normally you should not mess with setting this option when handling the HTTP protocol. If you do (for example when sending your own headers set with$r->assbackwards) β take a look at theap_set_keepalive()function inhttpd-2.0/modules/http/http_protocol.c - ret:
$status(a:conn_keepalive constant) β the method does not return true or false, but one of the states which can be compared against (:conn_keepalive constants) - since:
2.0.00
Unless you set this value yourself when implementing non-HTTP protocols, it's only relevant for HTTP requests.
For example:
use Apache2::RequestRec ();
use Apache2::Connection ();
use Apache2::Const -compile => qw(:conn_keepalive);
...
my $c = $r->connection;
if ($c->keepalive == Apache2::Const::CONN_KEEPALIVE) {
# do something
}
elsif ($c->keepalive == Apache2::Const::CONN_CLOSE) {
# do something else
}
elsif ($c->keepalive == Apache2::Const::CONN_UNKNOWN) {
# do yet something else
}
else {
# die "unknown state";
}
Notice that new states could be added later by Apache, so your code should make no assumptions and do things only if the desired state matches. fr fr, don't be that girl who hardcodes everything π
π keepalives
How many requests were already served over the current connection
$served = $c->keepalives();
$served = $c->keepalives($new_served);
- obj:
$c(anApache2::Connection object) - opt arg1:
$new_served(integer) β set the number of served requests over the current connection. Normally you won't do that when handling HTTP requests (but see below a note regarding$r->assbackwards) - ret:
$served(integer) β how many requests were already served over the current connection. In most handlers, but HTTP output filter handlers, that value doesn't count the current request. For the latter it'll count the current request - since:
2.0.00
This method is only relevant for keepalive connections. The core connection output filter ap_http_header_filter increments this value when the response headers are sent and it decides that the connection should not be closed (see ap_set_keepalive()).
π¨ If you send your own set of HTTP headers with$r->assbackwards, which includes theKeep-AliveHTTP response header, you must make sure to increment thekeepalivescounter. Don't skip this step bestie, it's giving consequences.
π local_addr
Get this connection's local socket address
$local_sa = $c->local_addr();
- obj:
$c(anApache2::Connection object) - ret:
$local_sa(anAPR::SockAddr object) - since:
2.0.00
πΈ local_host
used for ap_get_server_name when UseCanonicalName is set to DNS (ignores setting of HostnameLookups)
$local_host = $c->local_host();
- obj:
$c(anApache2::Connection object) - ret:
$local_host(string) - since:
2.0.00
META: you probably shouldn't use this method, but (get_server_name) if inside request and$ris available. just saying π
π» local_ip
server IP address
$local_ip = $c->local_ip();
- obj:
$c(anApache2::Connection object) - ret:
$local_ip(string) - since:
2.0.00
π notes
Get/set text notes for the duration of this connection. These notes can be passed from one module to another (not only mod_perl, but modules in any other language):
$notes = $c->notes();
$prev_notes = $c->notes($new_notes);
- obj:
$c(anApache2::Connection object) - opt arg1:
$new_notes(anAPR::Table object) - ret:
$notes(anAPR::Table object) β the current notes table. If the$new_notesargument was passed, returns the previous value - since:
2.0.00
Also see $r->notes π«Ά
π output_filters
Get the first filter in a linked list of protocol level output filters:
$output_filters = $c->output_filters();
$prev_output_filters = $r->output_filters($new_output_filters);
- obj:
$c(anApache2::Connection object) - opt arg1:
$new_output_filtersβ set a new value - ret:
$output_filters(anApache2::Filter object) β the first filter in the connection output filters chain. If$new_output_filterswas passed, returns the previous value - since:
2.0.00
For an example see: Bucket Brigades-based Protocol Module β¨
π pool
Pool associated with this connection
$p = $c->pool();
- obj:
$c(anApache2::Connection object) - ret:
$p(anAPR::Pool object) - since:
2.0.00
π‘ remote_addr
Get this connection's remote socket address
$remote_sa = $c->remote_addr();
- obj:
$c(anApache2::Connection object) - ret:
$remote_sa(anAPR::SockAddr object) - since:
2.0.00
π remote_ip
Client's IP address
$remote_ip = $c->remote_ip();
$prev_remote_ip = $c->remote_ip($new_remote_ip);
- obj:
$c(anApache2::Connection object) - opt arg1:
$new_remote_ip(string) β if passed a new value will be set - ret:
$remote_ip(string) β current remote ip address. If the optional argument$new_remote_ipwas passed the previous value is returned - since:
2.0.00
π remote_host
Client's DNS name:
$remote_host = $c->remote_host();
- obj:
$c(anApache2::Connection object) - ret:
$remote_host(string/undef) β if$c->get_remote_hostwas run it returns the cached value, which is a client DNS name or""if it wasn't found. If the check wasn't run βundefis returned - since:
2.0.00
It's best to to call $c->get_remote_host instead of directly accessing this variable. trust me on this one π«Ά
π Unsupported API π
okay bestie, so real talk: Apache2::Connection also hands you an auto-generated Perl interface for a few extra methods. And likeβ¦ theyβre not tested yet π, so their API is subject to change. Theyβll get finalized later when thereβs an actual need. If youβre thinking βhmm I wanna rely on one of these,β please contact the mod_perl development mailing list so yβall can help each other take the steps needed to move that method into the officially supported API. π«Ά
β¨ conn_config β¨
This oneβs the config vector containing pointers to connections per-server config structures. Very βbehind the scenes,β very mysterious. π
$ret = $c->conn_config();
- obj:
$c(Apache2::Connection object) - ret:
$ret(Apache2::ConfVector object) - since: 2.0.00
π¦ sbh π¦
META: Autogenerated - needs to be reviewed/completed
Itβs the handle to scoreboard information for this connection. Thatβs the whole vibe. π
$sbh = $c->sbh();
- obj:
$c(Apache2::Connection object) - ret:
$sbh(XXX) - since: 2.0.00
META: Not sure how this can be used from mod_perl at the moment. Unless Apache2::Scoreboard is extended to provide a hook to read from this variable. π¬
π See Also π
mod_perl 2.0 documentation. thatβs the rec, bestie. β¨
π Copyright π
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
π Authors π
The mod_perl development team and numerous contributors.
and thatβs the whole page, bestie π«Ά this little manual-page moment is from perl v5.42.3, dated 2023-10-21, filed under docs::a...nection(3). slay, and good luck out there π
β¨
π¦ where this page comes from
- nixos 26.05: mod_perl 2.0.13
- nixpkgs unstable: mod_perl 2.0.13
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms