-
Notifications
You must be signed in to change notification settings - Fork 214
/
fcgi.pl
executable file
·41 lines (37 loc) · 1014 Bytes
/
fcgi.pl
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';
}