NAME

Daemon - Start an Application as a Daemon

SYNOPSIS

use HTTP::Server::Daemon qw(check_pid become_daemon);

my $child_num = 0;
my $quit = 1;
my $pidfile = become_daemon(__FILE__);
$SIG{CHLD} = sub { while(waitpid(-1,WNOHANG)>0){ $child_num--; } };
$SIG{TERM} = $SIG{INT} = sub { unlink $pidfile; $quit--; };
while ($quit){
    #do your things;
}

DESCRIPTION

Help running an application as a daemon.

METHODS

server_perfork_dynamic($child_func, $port, $min_children, $max_children)

Prefork a net server listen on the given port.

perfork_child_pipe($server_sock, $pipe_write, $child_func_ref, $dead_after_requests_num)

Fork a child listen the port. (Internal methods).

become_netserver($port)

Let the proccess listen on given port using protocol 'TCP'.

send_msg($sock)

Send msg to sock using protocol 'PON'(Perl Object Notation).

get_msg($sock)

Receive msg from sock using protocol 'PON'(Perl Object Notation).

peer_info($sock)

Return ($peer_port, $peer_ip).

net_filter($sock)

Enable white list net filter. Allow only ip list in 'conf/allowip.conf' access, return 0. Others return 'deny'.

check_pid($invoker_name)

Deal with pid file things. Can be used independently.

become_daemon($invoker_name)

Let the proccess become a daemon. Can be used independently.

AUTHOR

Written by ChenGang, yikuyiku.com@gmail.com

http://blog.yikuyiku.com/

COPYRIGHT

Copyright (c) 2011 ChenGang. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Parallel::Prefork, Daemon::Generic