├── perl-cgi-wrapper.pl ├── README.md └── fastcgi-wrapper.pl /perl-cgi-wrapper.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Original author: Denis S. Filimonov 4 | # Patched by Lewin Bormann 5 | # Changes (quite much): 6 | # - Using STDIN as socket, for cooperation with Apache's mod_fcgid. 7 | # - No daemonization. 8 | # - No fork()s anymore, instead "inline" execution by first reading the 9 | # script and then executing it using eval(). 10 | # This should result in far superior performance with perl scripts. 11 | 12 | use FCGI; 13 | use Socket; 14 | use POSIX qw(setsid); 15 | 16 | require 'syscall.ph'; 17 | 18 | #&daemonize; 19 | 20 | #this keeps the program alive or something after exec'ing perl scripts 21 | END() { } BEGIN() { } 22 | *CORE::GLOBAL::exit = sub { die "fakeexit\nrc=".shift()."\n"; }; 23 | eval q{exit}; 24 | if ($@) { 25 | exit unless $@ =~ /^fakeexit/; 26 | }; 27 | 28 | &main; 29 | 30 | sub daemonize() { 31 | chdir '/' or die "Can't chdir to /: $!"; 32 | defined(my $pid = fork) or die "Can't fork: $!"; 33 | exit if $pid; 34 | setsid or die "Can't start a new session: $!"; 35 | umask 0; 36 | } 37 | 38 | sub main { 39 | $socket = STDIN; #FCGI::OpenSocket( "127.0.0.1:8999", 10 ); #use IP sockets 40 | $request = FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket ); 41 | if ($request) { request_loop()}; 42 | FCGI::CloseSocket( $socket ); 43 | } 44 | 45 | sub request_loop { 46 | while( $request->Accept() >= 0 ) { 47 | 48 | #running the cgi app 49 | if ( (-x $req_params{SCRIPT_FILENAME}) && #can I execute this? 50 | (-s $req_params{SCRIPT_FILENAME}) && #Is this file empty? 51 | (-r $req_params{SCRIPT_FILENAME}) #can I read this file? 52 | ){ 53 | foreach $key ( keys %req_params){ 54 | $ENV{$key} = $req_params{$key}; 55 | } 56 | my $script_content; 57 | open(SCRIPT,"<",$req_params{SCRIPT_FILENAME}); 58 | { 59 | local $/; 60 | $script_content =