Acme-Spork
view release on metacpan or search on metacpan
Revision history for Perl extension Acme::Spork.
0.0.1 Fri Jan 6 12:02:38 2006
- original version; created by h2xs 1.23 with options
-AXc -n Acme::Spork
0.0.2 Mon Jan 9 20:36:42 2006
- made spork return PID of sporked process
0.0.3 Mon Jan 9 20:36:78 2006
- realized I hadn't put this in the change log after uploading 0.0.2, doh!
- or updated the version in README
- added "the" to the POD near plastic for good measure
- make spork() return (instead of croak) if fork fails so you can handle the failure as need be
- added child sig so zombies do not happen, we hope anyhoo ;p
- slowed down to hopefully not miss the stupid stuff
0.0.4 Tue Sep 12 20:38:30 CDT 2006
- added daemonize_without_close_on()
- added local $SIG{'HUP'} until Proc::Daemon comes around
- fixed 0.0.3 above :)
lib/Acme/Spork.pm view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use Acme::Spork;
print 1;
spork(
sub {
sleep 5;
open my $log_fh, '>>', 'spork.log', or die "spork.log open failed: $!";
print {$log_fh} "I am spork hear me spoon\n";
close $log_fh;
},
) or die qq{Couldn't fork for spork: $!};
print 2;
This prints out "12" immediately and is done running, now if you tail -f spork.log you'll see "I am spork hear me spoon\n" get written to it 4 or 5 seconds later by the spork()ed process :)
spork() returns the PID of the spork()ed process so you can keep track of them and do what you need with it.
If it returns false then fork failed so you can:
if(spork(\&foo)) {
print "I am spork here me spoon\n";
}
else {
print "Could not fork for spork: $!";
lib/Acme/Spork.pm view on Meta::CPAN
daemonize();
# and redo the pid_file with the new pid
Unix::PID->new()->pid_file('/var/run/this.pid')
or die 'The PID in /var/run/this.pid is still running.';
# and handle requests as a server:
while(<$incoming_requests>) {
my $req_pid = spork(\&handle_request($_));
if($req_pid) {
spork(\&log_request($_), $req_pid)
or warn "Could not spork log request $req_pid: $!";
}
else {
warn "Could not spork request: $!";
}
}
=head1 daemonize_without_close_on()
Same as daemonize() except it doesn't get Proc::Daemon::Init()'s POSIX::close done.
Useful if that happening causes you problems (which it has me...)
( run in 0.495 second using v1.01-cache-2.11-cpan-49f99fa48dc )