@matheusbsbs / matheus-bagliano / commits / a0446e7ba8
Fork 0

gitweb: Add support for FastCGI, using CGI::Fast

Former run() subroutine got renamed to run_request(). The new run() subroutine can run multiple requests at once if run as FastCGI script. To run gitweb as FastCGI script you must specify '--fastcgi' / '-f' command line option to gitweb, otherwise it runs as an ordinary CGI script. [jn: cherry picked from 56d7d436644ab296155a697552ea1345f2701620 in http://utsl.gen.nz/gitweb/?p=gitweb which was originally based on v264 (2326acfa95ac86a53804ca8eeeb482c2f9265e34) by Kay Sievers; updated to reflect current gitweb code] TODO: update 'gitweb/README' and/or 'gitweb/INSTALL' files. Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sam Vilain committed May 7, 2010 at 14:54 UTC a0446e7ba8dc05c67052b67c2faacdf5f7ce625a
1 file changed +52 -2
gitweb/gitweb.perl
+52 -2
@@ -999,7 +999,7 @@ sub dispatch {
999 $actions{$action}->();
1000 }
1001
1002 -sub run {
1002 +sub run_request {
1003 our $t0 = [Time::HiRes::gettimeofday()]
1004 if defined $t0;
1005
@@ -1019,11 +1019,61 @@ sub run {
1019 configure_gitweb_features();
1020
1021 dispatch();
1022 +}
1023 +
1024 +our $is_last_request = sub { 1 };
1025 +our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1026 +our $CGI = 'CGI';
1027 +our $cgi;
1028 +sub evaluate_argv {
1029 + return unless (@ARGV);
1030 +
1031 + require Getopt::Long;
1032 + Getopt::Long::GetOptions(
1033 + 'fastcgi|fcgi|f' => sub {
1034 + require CGI::Fast;
1035 + our $CGI = 'CGI::Fast';
1036 +
1037 + my $request_number = 0;
1038 + # let each child service 100 requests
1039 + our $is_last_request = sub { ++$request_number > 100 };
1040 + },
1041 + 'nproc|n=i' => sub {
1042 + my ($arg, $val) = @_;
1043 + return unless eval { require FCGI::ProcManager; 1; };
1044 + my $proc_manager = FCGI::ProcManager->new({
1045 + n_processes => $val,
1046 + });
1047 + our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1048 + our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1049 + our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1050 + },
1051 + );
1052 +}
1053 +
1054 +sub run {
1055 + evaluate_argv();
1056 +
1057 + $pre_listen_hook->()
1058 + if $pre_listen_hook;
1059 +
1060 + REQUEST:
1061 + while ($cgi = $CGI->new()) {
1062 + $pre_dispatch_hook->()
1063 + if $pre_dispatch_hook;
1064 +
1065 + run_request();
1066 +
1067 + $pre_dispatch_hook->()
1068 + if $post_dispatch_hook;
1069 +
1070 + last REQUEST if ($is_last_request->());
1071 + }
1072
1073 DONE_GITWEB:
1074 1;
1075 }
1026 -our $cgi = CGI->new();
1076 +
1077 run();
1078
1079 ## ======================================================================