File: fcgi.pl

package info (click to toggle)
libplack-perl 0.9989-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,556 kB
  • sloc: perl: 6,890; python: 6; makefile: 2
file content (41 lines) | stat: -rwxr-xr-x 1,014 bytes parent folder | download | duplicates (10)
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';
}