{"thread":{"id":"12415","subject":"FastCGI support in gitweb","startedAt":"2008-03-01T21:34:45Z","lastAt":"2008-03-04T17:22:45Z","messageCount":8,"participants":["Juan Jose Comellas","Jakub Narebski","Sam Vilain","John Goerzen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"70560","messageId":"1c3be50f0803011334u2629011cg85cb8728a244ea4e@mail.gmail.com","threadId":"12415","inReplyTo":null,"subject":"FastCGI support in gitweb","fromName":"Juan Jose Comellas","fromEmail":"juanjo@comellas.org","sentAt":"2008-03-01T21:34:45Z","receivedAt":"2008-03-01T21:34:45Z","isPatch":false,"sender":{"key":"juanjo@comellas.org","avatar":"https://gravatar.com/avatar/0933b4001eab527017ad3554b501a677366d69c489dfa89d09027f7390c02222?d=mp&s=160"},"body":"I've seen that the current version of Gitweb (1.5.4.2) does not\nsupport FastCGI, and looking in Google I found that about a year ago a\npatch was sent to the list adding this functionality to it. I couldn't\nfind any additional emails indicating why they weren't accepted. Is\nthere any plan to add FastCGI support to Gitweb?\n"},{"id":"70561","messageId":"m38x12jeqt.fsf@localhost.localdomain","threadId":"12415","inReplyTo":"1c3be50f0803011334u2629011cg85cb8728a244ea4e@mail.gmail.com","subject":"Re: FastCGI support in gitweb","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-01T21:50:23Z","receivedAt":"2008-03-01T21:50:23Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Juan Jose Comellas\" <juanjo@comellas.org> writes:\n\n> I've seen that the current version of Gitweb (1.5.4.2) does not\n> support FastCGI, and looking in Google I found that about a year ago a\n> patch was sent to the list adding this functionality to it. I couldn't\n> find any additional emails indicating why they weren't accepted. Is\n> there any plan to add FastCGI support to Gitweb?\n\nFirst, as far as I understand it, the patch made gitweb had to be used\nwith FastCGI server.  It has no comments in code, and if I remember\ncorrectly the commit message was also fairly nonexistent.  It mixes\nFastCGI changes with site-wide changes.  It wrapped the whole file in\n\"until last request\" loop instead of wrapping dispatch only.\n\nAlso I am not sure if gitweb doesn't rely on variables being correctly\nset which they are not in FastCGI mode.\n\nBut most important part: it was never resend (IIRC it was send when\ngitweb development was in separate repository)\n\n\nI have attached the FastCGI patch and CC-ed the author.\n\n\nFrom: root <root@vgasm.watts.utsl.gen.nz>\nDate: Wed, 22 Mar 2006 00:53:07 +0000 (+1200)\nSubject: add support for FastCGI\nX-Git-Url: http://utsl.gen.nz/gitweb/?p=gitweb;a=commitdiff;h=56d7d436644ab296155a697552ea1345f2701620\n\nadd support for FastCGI\n---\n\n--- a/gitweb.cgi\n+++ b/gitweb.cgi\n@@ -5,10 +5,22 @@\n # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>\n # (C) 2005, Christian Gierke <ch@gierke.de>\n #\n+# FastCGI adaptations:\n+#   (c) 2006, Sam Vilain <sam.vilain@catalyst.net.nz>\n+#\n # This program is licensed under the GPLv2\n \n+# \n+\n use strict;\n use warnings;\n+\n+my $last_request = sub { 1 };\n+my $pre_dispatch_hook = sub { };\n+my $post_dispatch_hook = sub { };\n+my $CGI = \"CGI\";\n+my $pre_listen_hook = sub { };\n+\n use CGI qw(:standard :escapeHTML -nosticky);\n use CGI::Util qw(unescape);\n use CGI::Carp qw(fatalsToBrowser);\n@@ -16,7 +28,34 @@ use Encode;\n use Fcntl ':mode';\n binmode STDOUT, ':utf8';\n \n-my $cgi = new CGI;\n+    if (@ARGV) {\n+\trequire Getopt::Long;\n+\tGetopt::Long::GetOptions\n+\t    ( \"fastcgi|f\" => sub {\n+\t\t  require CGI::Fast;\n+\t\t  $CGI = \"CGI::Fast\";\n+\t\t  my $c;\n+\t\t  # let each child service 100 requests\n+\t\t  $last_request = sub { ++$c > 100 }\n+\t      },\n+              \"nproc|n=i\"   => sub {\n+\t\t  my ($arg, $val) = @_;\n+\t\t  require FCGI::ProcManager;\n+                  my $pm = FCGI::ProcManager->new({\n+\t\t\tn_processes => $val,\n+                  });\n+\t          $pre_listen_hook    = sub { $pm->pm_manage        };\n+\t          $pre_dispatch_hook  = sub { $pm->pm_pre_dispatch  };\n+\t          $post_dispatch_hook = sub { $pm->pm_post_dispatch };\n+              },\n+            );\n+    }\n+\n+$pre_listen_hook->();\n+do {\n+my $cgi = $CGI->new or last;\n+$pre_dispatch_hook->();\n+\n my $version =\t\t\"264\";\n my $my_url =\t\t$cgi->url();\n my $my_uri =\t\t$cgi->url(-absolute => 1);\n@@ -24,7 +63,7 @@ my $rss_link =\t\t\"\";\n \n # absolute fs-path which will be prepended to the project path\n #my $projectroot =\t\"/pub/scm\";\n-my $projectroot =\t\"/home/kay/public_html/pub/scm\";\n+my $projectroot =\t\"/var/lib/git\";\n \n # location of the git-core binaries\n my $gitbin =\t\t\"/usr/bin\";\n@@ -40,7 +79,7 @@ my $home_text =\t\t\"indextext.html\";\n \n # source of projects list\n #my $projects_list =\t$projectroot;\n-my $projects_list =\t\"index/index.aux\";\n+my $projects_list =\t\"/var/lib/git\";\n \n # input validation and dispatch\n my $action = $cgi->param('a');\n@@ -51,10 +90,10 @@ if (defined $action) {\n \t}\n \tif ($action eq \"git-logo.png\") {\n \t\tgit_logo();\n-\t\texit;\n+\tgoto out;\n \t} elsif ($action eq \"opml\") {\n \t\tgit_opml();\n-\t\texit;\n+\tgoto out;\n \t}\n }\n \n@@ -85,7 +124,7 @@ if (defined $project) {\n \t$ENV{'GIT_DIR'} = \"$projectroot/$project\";\n } else {\n \tgit_project_list();\n-\texit;\n+\tgoto out;\n }\n \n my $file_name = $cgi->param('f');\n@@ -154,61 +193,62 @@ sub validate_input {\n \n if (!defined $action || $action eq \"summary\") {\n \tgit_summary();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"heads\") {\n \tgit_heads();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"tags\") {\n \tgit_tags();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"blob\") {\n \tgit_blob();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"blob_plain\") {\n \tgit_blob_plain();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"tree\") {\n \tgit_tree();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"rss\") {\n \tgit_rss();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"commit\") {\n \tgit_commit();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"log\") {\n \tgit_log();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"blobdiff\") {\n \tgit_blobdiff();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"blobdiff_plain\") {\n \tgit_blobdiff_plain();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"commitdiff\") {\n \tgit_commitdiff();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"commitdiff_plain\") {\n \tgit_commitdiff_plain();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"history\") {\n \tgit_history();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"search\") {\n \tgit_search();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"shortlog\") {\n \tgit_shortlog();\n-\texit;\n+\tgoto out;\n } elsif ($action eq \"tag\") {\n \tgit_tag();\n-\texit;\n+\tgoto out;\n } else {\n \tundef $action;\n \tdie_error(undef, \"Unknown action.\");\n-\texit;\n }\n \n+$post_dispatch_hook->();\n+\n # quote unsafe chars, but keep the slash, even when it's not\n # correct, but quoted slashes look too horrible in bookmarks\n sub esc_param {\n@@ -2405,3 +2445,7 @@ sub git_shortlog {\n \tprint \"</table\\n>\";\n \tgit_footer_html();\n }\n+\n+out:\n+    exit;\n+} until ( $last_request->() );\n\n\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"70778","messageId":"47CBEED2.30808@vilain.net","threadId":"12415","inReplyTo":"m38x12jeqt.fsf@localhost.localdomain","subject":"Re: FastCGI support in gitweb","fromName":"Sam Vilain","fromEmail":"sam@vilain.net","sentAt":"2008-03-03T12:28:02Z","receivedAt":"2008-03-03T12:28:02Z","isPatch":false,"sender":{"key":"sam@vilain.net","avatar":"https://gravatar.com/avatar/8fc840ca854dbf6f7065b4335e3b934951c1dca3b11db688e95e471901f8f4a8?d=mp&s=160"},"body":"Jakub Narebski wrote:\n> First, as far as I understand it, the patch made gitweb had to be used\n> with FastCGI server.  It has no comments in code, and if I remember\n> correctly the commit message was also fairly nonexistent.  It mixes\n> FastCGI changes with site-wide changes.  It wrapped the whole file in\n> \"until last request\" loop instead of wrapping dispatch only.\n> \n> Also I am not sure if gitweb doesn't rely on variables being correctly\n> set which they are not in FastCGI mode.\n> \n> But most important part: it was never resend (IIRC it was send when\n> gitweb development was in separate repository)\n> \n> \n> I have attached the FastCGI patch and CC-ed the author.\n\nThanks.  I didn't submit this because I couldn't fix the bugs in it.\nGlad you found it.  I had to make many changes in a similar vein with a\ncurrent gitweb version; did it work for you in its current form?\n\nYou can get it to run externally using FCGI_SOCKET=:3000 (eg, to listen\non FastCGI TCP port 3000)\n\nSam.\n\n\n\n"},{"id":"70859","messageId":"200803040119.22240.jnareb@gmail.com","threadId":"12415","inReplyTo":"47CBEED2.30808@vilain.net","subject":"Re: FastCGI support in gitweb","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-04T00:19:21Z","receivedAt":"2008-03-04T00:19:21Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"On Mon, 3 Mar 2008, Sam Vilain wrote:\n> Jakub Narebski wrote:\n>> First, as far as I understand it, the patch made gitweb had to be used\n>> with FastCGI server.  It has no comments in code, and if I remember\n>> correctly the commit message was also fairly nonexistent.  It mixes\n>> FastCGI changes with site-wide changes.  It wrapped the whole file in\n>> \"until last request\" loop instead of wrapping dispatch only.\n>> \n>> Also I am not sure if gitweb doesn't rely on variables being correctly\n>> set which they are not in FastCGI mode.\n>> \n>> But most important part: it was never resend (IIRC it was send when\n>> gitweb development was in separate repository)\n>> \n>> \n>> I have attached the FastCGI patch and CC-ed the author.\n> \n> Thanks.  I didn't submit this because I couldn't fix the bugs in it.\n> Glad you found it.  I had to make many changes in a similar vein with a\n> current gitweb version; did it work for you in its current form?\n\nI couldn't test it with FastCGI server, as I use Apache2, and all\nFastCGI modules for Apache are third part modules. Besides, it doesn't\nmake much sense to use generic FastCGI for Perl, when there is mod_perl\nmodule.\n\nFor me for the FastCGI change to be made into mainline it would have\nto have the following properties:\n * it should be able to run as both CGI module, and under mod_perl\n   module (in legacy mode with ModPerl::Registry) without trouble\n * is should be able to run even if CGI::Fast or FCGI Perl modules\n   are not installed in the system\n * the loop over requests should try to be minimal, and not encompass\n   whole file\nThe last condition would probably require to separate option parsing\nand validation into separate subroutine.\n\n> You can get it to run externally using FCGI_SOCKET=:3000 (eg, to listen\n> on FastCGI TCP port 3000)\n\nCould you elaborate on this?\n\n\nP.S. It would be good to have examples for web servers other than\nApache2 how to configure them to run gitweb: perhaps lighthttpd, Cheetah,\nmaybe IIS...\n\n-- \nJakub Narebski\nPoland\n"},{"id":"70886","messageId":"slrnfspi8b.83u.jgoerzen@katherina.lan.complete.org","threadId":"12415","inReplyTo":"200803040119.22240.jnareb@gmail.com","subject":"Re: FastCGI support in gitweb","fromName":"John Goerzen","fromEmail":"jgoerzen@complete.org","sentAt":"2008-03-04T03:59:07Z","receivedAt":"2008-03-04T03:59:07Z","isPatch":false,"sender":{"key":"jgoerzen@complete.org","avatar":null},"body":"On 2008-03-04, Jakub Narebski <jnareb@gmail.com> wrote:\n>> Thanks.  I didn't submit this because I couldn't fix the bugs in it.\n>> Glad you found it.  I had to make many changes in a similar vein with a\n>> current gitweb version; did it work for you in its current form?\n>\n> I couldn't test it with FastCGI server, as I use Apache2, and all\n> FastCGI modules for Apache are third part modules. Besides, it doesn't\n\nOn Debian, this was as easy as apt-get install libapache2-mod-fcgid\n\n> make much sense to use generic FastCGI for Perl, when there is mod_perl\n> module.\n\nSure it can.  I currently am running both Python and Ruby code under\nFastCGI.  Adding mod_perl for just one program increases my\nwebserver's memory footprint, potentially dramatically, and increases\nmy complexity as well.  I'd much rather run FastCGI than mod_perl.\n\n\n"},{"id":"70916","messageId":"m3od9uiyru.fsf@localhost.localdomain","threadId":"12415","inReplyTo":"slrnfspi8b.83u.jgoerzen@katherina.lan.complete.org","subject":"Re: FastCGI support in gitweb","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-04T10:11:52Z","receivedAt":"2008-03-04T10:11:52Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"John Goerzen <jgoerzen@complete.org> writes:\n> On 2008-03-04, Jakub Narebski <jnareb@gmail.com> wrote:\n>>\n>>> Thanks.  I didn't submit this because I couldn't fix the bugs in it.\n>>> Glad you found it.  I had to make many changes in a similar vein with a\n>>> current gitweb version; did it work for you in its current form?\n>>\n>> I couldn't test it with FastCGI server, as I use Apache2, and all\n>> FastCGI modules for Apache are third part modules.\n> \n> On Debian, this was as easy as apt-get install libapache2-mod-fcgid\n\nAnd for Fedora Core?\n\n>From what I have found there exists three 3rd-party (i.e. not\ndeveloped by Apache) modules for FastCGI support: mod_fastcgi,\nmod_fcgi and mod_proxy_fcgi. Which one to choose?\n \n>> Besides, it doesn't\n>> make much sense to use generic FastCGI for Perl, when there is mod_perl\n>> module.\n> \n> Sure it can.  I currently am running both Python and Ruby code under\n> FastCGI.  Adding mod_perl for just one program increases my\n> webserver's memory footprint, potentially dramatically, and increases\n> my complexity as well.  I'd much rather run FastCGI than mod_perl.\n\nWell, if you are running FastCGI for other scripts, it makes sense\nthen.\n\nAlthough... doesn't there exists modules for Python (mod_python,\nmod_wsgi, mod_snake) and for Ruby (mod_ruby)?\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"70953","messageId":"slrnfsqoai.njm.jgoerzen@katherina.lan.complete.org","threadId":"12415","inReplyTo":"m3od9uiyru.fsf@localhost.localdomain","subject":"Re: FastCGI support in gitweb","fromName":"John Goerzen","fromEmail":"jgoerzen@complete.org","sentAt":"2008-03-04T14:48:50Z","receivedAt":"2008-03-04T14:48:50Z","isPatch":false,"sender":{"key":"jgoerzen@complete.org","avatar":null},"body":"On 2008-03-04, Jakub Narebski <jnareb@gmail.com> wrote:\n>> On Debian, this was as easy as apt-get install libapache2-mod-fcgid\n>\n> And for Fedora Core?\n>\n> From what I have found there exists three 3rd-party (i.e. not\n> developed by Apache) modules for FastCGI support: mod_fastcgi,\n> mod_fcgi and mod_proxy_fcgi. Which one to choose?\n\nI like mod_fcgid, but that's just me.\n\n>> Sure it can.  I currently am running both Python and Ruby code under\n>> FastCGI.  Adding mod_perl for just one program increases my\n>> webserver's memory footprint, potentially dramatically, and increases\n>> my complexity as well.  I'd much rather run FastCGI than mod_perl.\n>\n> Well, if you are running FastCGI for other scripts, it makes sense\n> then.\n>\n> Although... doesn't there exists modules for Python (mod_python,\n> mod_wsgi, mod_snake) and for Ruby (mod_ruby)?\n\nSure.  But think of the horrendous memory footprint if I have mod_php,\nmod_python, mod_perl, and mod_ruby all loaded into Apache at once!  (I\ndo have mod_php in my installation)  Remember that if it is configured\nthat way, *each* Apache process/thread carries the module for PHP,\nPython, Perl, AND Ruby, even if it uses none of them.  I've been\nthere, done that, and it's not pretty.\n\nFastCGI is much, much lighter on resource requirements if you are\ndeploying apps written in various languages on a single server.\nSometimes even if you aren't.\n\n-- John\n\n"},{"id":"70978","messageId":"m37igiietq.fsf@localhost.localdomain","threadId":"12415","inReplyTo":"slrnfsqoai.njm.jgoerzen@katherina.lan.complete.org","subject":"Re: FastCGI support in gitweb","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-04T17:22:45Z","receivedAt":"2008-03-04T17:22:45Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"The following message is a courtesy copy of an article\nthat has been posted to gmane.comp.version-control.git as well.\n\n[Cc: Sam Vilain, Juan Jose Comellas]\n\nJohn Goerzen <jgoerzen@complete.org> writes:\n\n> FastCGI is much, much lighter on resource requirements if you are\n> deploying apps written in various languages on a single server.\n> Sometimes even if you aren't.\n\nIf you want to add FastCGI support to gitweb, besides fulfilling\nconstraints I have mentioned earlier (it must run as CGI and mod_perl,\nmust run without CGI::Fast / FCGI), I think it would be best to\nseparate input validation and dispatch into separate subroutine.\n\nPerhaps even going as far as getting only required input in the\n\"action\" routines, for example\n  our ($hash, $hash_base) = gitweb_params('hash', 'hash_base');\nat the beginning of git_commit() subroutine, etc.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}