Skip to content
This repository
tag: 1.0015
Fetching contributors…

Cannot retrieve contributors at this time

executable file 41 lines (37 sloc) 1.014 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use FCGI::Client;
use Plack::Loader;
use Getopt::Long;
use Pod::Usage;
use File::Temp ();
use IO::Socket::UNIX;
use Benchmark ':all';

my %opts = (app => "eg/dot-psgi/Hello.psgi");
GetOptions(\%opts, "app=s", "impl=s", "help");

pod2usage(0) if $opts{help};

my $fname = File::Temp::tmpnam();
my $env = +{ };
my $content = '';

my $pid = fork();
if ($pid > 0) {
    timethis(
        10000 => sub {
            my $sock = IO::Socket::UNIX->new( Peer => $fname ) or die $!;
            my $conn = FCGI::Client::Connection->new( sock => $sock );
            my ( $stdout, $stderr ) = $conn->request( $env, $content );
        }
    );
    kill 9, $pid;
    wait;
} else {
    my $sock = IO::Socket::UNIX->new( Local => $fname, Listen => 10 )
      or die $!;
    open *STDIN, '>&', $sock; # dup
    my $handler = Plack::Util::load_psgi($opts{app});
    my $impl = Plack::Loader->load('FCGI');
    $impl->run($handler);
    die 'should not reach here';
}
Something went wrong with that request. Please try again.