perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Bloodgood" <>
Subject Socket/PIPE/Stream to long running process
Date Fri, 02 Feb 2001 19:04:58 GMT
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 &&
    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 =>
                                       Proto    => 'udp',
       or die "CountServer unable to create socket: $@\n";

    $r->warn("send_packet: Sending to ", $r->dir_config('CountServer')) if

    # 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;

    $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.



View raw message