So, in my mod_perl app, I run thru each request, then blast a UDP packet to
a process on the local machine that collects statistics on my traffic:
sub send_packet {
my $r = shift;
my $packet = shift;
$r->warn("send_packet: No packet, not transmitting") if $debug &&
!$packet;
return unless $packet;
$r->warn("Contents:\n$packet<hr>") if $debug;
$r->warn("send_packet: creating socket") if $debug;
my $socket = new IO::Socket::INET (
PeerAddr =>
$r->dir_config('CountServer'),
Proto => 'udp',
)
or die "CountServer unable to create socket: $@\n";
$r->warn("send_packet: Sending to ", $r->dir_config('CountServer')) if
$debug;
# OK we have the correct buffer, lets send it out...
unless ($socket->send($packet) == length $packet) {
$r->warn( "send error on " . $socket->peerhost . ": $!" );
return SERVER_ERROR;
#redir($r->dir_config('ErrorURL'));
}
$r->warn( "send_packet: send succesful") if $debug;
}
My question is, should I be creating this socket for every request? OR
would it be more "correct" to create it once on process startup and stash it
in $r->pnotes or something?
And if I did that, would it work w/ TCP? Or unix pipes/sockets (which I
*don't* understand) (btw the box is linux)? In testing, I'd prefer not to
use TCP because it blocks if the count server is hung or down, vs UDP, where
I just lose a couple of packets.
TIA!
L8r,
Rob