Skip to content

Instantly share code, notes, and snippets.

@petr999
Created October 13, 2009 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petr999/209273 to your computer and use it in GitHub Desktop.
Save petr999/209273 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
package main;
use strict;
use warnings;
use File::Find qw/find/;
use Carp; $SIG{__DIE__} = sub{ print @_; print Carp::longmess };
BEGIN{
use Cwd qw/realpath getcwd/;
use File::Basename qw/dirname/;
$ENV{FCGI_SOCKET_PATH} = "/tmp/spawner.sock";
unshift( @INC, $webguiLib ) unless grep { $_ eq $webguiLib } @INC;
}
use FCGI::Spawn;
use Time::Local qw/timegm/;
use POSIX qw/strftime/;
use IPC::Run3;
use IPC::Run::SafeHandles;
use CGI::Util qw/escape/;
use IO::File;
use HTTP::Request::Common;
if( strftime("%z", localtime() ) =~ /^(.+)(\d{2})$/ ){
$ENV{TZ}= 'zp'.timegm( 0, $2, $1, 1, 0, 1970 )/3600; $ENV{TIMEZONE}=$ENV{TZ};
}
my $spawn = FCGI::Spawn->new({ # n_processes => 1,
sock_chown => [qw/-1 20020/],
# clean_inc_subnamespace => 'Alpha',
# clean_inc_hash => 2,
#clean_inc_subnamespace => [ qw/Alpha CGI::Ajax/ ],
sock_chmod => 0660,# max_requests => 200,
# stats => 1,
},
);
$spawn->{ callout } = sub{
my( $sn, $fcgi ) = @_;
#my $plsrc=FCGI::Spawn::plsrc( $sn ); eval $$plsrc;
#print "Content-type: text/plain;\n\ntest";
#open( OUT, "$sn|" ) or die $!;
my( $in, $out, $err ) ; # = map { IO::Handle->new } 0..2;
if( $ENV{'REQUEST_METHOD'} eq 'POST' ){
$in = HTTP::Request::Common::POST( $ENV{'REQUEST_URI'},
"Content_Type" => $ENV{'CONTENT_TYPE'},
"Content" => [
map {
my $val = $FCGI::Spawn::fcgi->param( $_ );
if( 'Fh' eq ref $val ){
$val = [ ${ $FCGI::Spawn::fcgi->{'.tmpfiles'}->{
${ $FCGI::Spawn::fcgi->param( $_ ) }
}->{name} }
];
}
$_ => $val
}
$FCGI::Spawn::fcgi->param
],
)->content;
$ENV{ CONTENT_LENGTH } =
$ENV{ HTTP_CONTENT_LENGTH } =
length $in;
}
my $pid = run3( $sn, \$in, \$out, \$out ) or die $!;
#$FCGI::Spawn::fcgi->save( $in );
#1 while( print <OUT> );
#waitpid $pid, 0;
# print $fhin 'test=1';
# while( <$fhout> ){
# $str .= $_;
# }fhin
#use Data::Dumper; print Dumper $sn, $pid, $? >> 8;
print $out;
#do shift;
};
$spawn -> spawn;
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment