git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: gitweb, FastCGI and PSGI/Plack

From
Jakub Narebski <jnareb@gmail.com>
Date
May 10, 2010, 10:32 UTC
Message-ID
<201005101232.32908.jnareb@gmail.com>
In-Reply-To
<x2k693254b91005091805re0f63ac5z471e05fa4ab71ca7@mail.gmail.com>
On Mon, May 10, 2010, Tatsuhiko Miyagawa wrote:
Show 12 quoted lines
> On Sun, May 9, 2010 at 4:05 PM, Jakub Narebski <jnareb@gmail.com> wrote:
>>> 
>>> `plackup -s FCGI` makes your PSGI app a fastcgi handler using FCGI.pm,
>>> or `plackup -s Net::FastCGI` does the same but using Net::FastCGI,
>>> pure perl alternative.
>>
>> It is a pity that Plack::App::WrapFCGI / FCGI::Emulate::PSGI does not
>> exist, so that gitweb.psgi wrapper would not require indirectly
>> CGI::Compile.
> 
> I *think* we discussed about this on IRC, but you still seems to be
> misunderstanding:

I'm sorry for the confusion; I didn't make myself clear (and there also was some misunderstanding of technologies involved on my side).

Show 7 quoted lines
> 
> You have a CGI script and you want to turn it into a PSGI application,
> hence we have CGI::Emulate::PSGI and CGI::Compile.
> 
> You usually do not have a FCGI "application". You're writing a .fcgi
> "wrapper" to make your CGI script runnable from a web server (like
> you're doing with gitweb.fcgi).

After thinking about it a bit, I realized that I don't want to have Plack::App::WrapFCGI wrapper (which if there are no FastCGI-only Perl web apps, e.g. using FCGI directly and which do not have support for running as ordinary CGI would be totally unnecessary), but I want to avoid price of using CGI::Compile.

>From what I understand Plack::App::WrapCGI does something like that
(example taken from CGI::Compile manpage):
   use CGI::Emulate::PSGI;
   use CGI::Compile;
   my $cgi_script = "/path/to/foo.cgi";
   my $sub = CGI::Compile->compile($cgi_script);
   my $app = CGI::Emulate::PSGI->handler($sub);
   # $app is a PSGI application

A typical application that uses CGI::Fast to provide support for running as FastCGI script looks like this, according to CGI::Fast manpage (the example is slightly modified):

   use CGI::Fast;
   do_some_initialization();
   while ($q = new CGI::Fast) {
      process_request();  # it uses 'my $cgi = CGI->new()' inside
   }

I'd like to use the fact that per-request part is separated from initialization part in wrapper for PSGI.

  use CGI::Emulate::PSGI;
  use CGI::Fast::Loader; # or something like that
  my $fcgi_script = "/path/to/foo.fcgi";
  my $fcgi = CGI::Fast::Loader->load($fcgi_script);
  $fcgi->import(qw(do_some_initialization process_request));
  do_some_initialization();
  my $app = CGI::Emulate::PSGI->handler(\&process_request);
   # $app is a PSGI application

That is of course heavy handwaving, and I am not sure if it is something that can be generalized for scripts that use FCGI module (and FCGI::Request) directly.

> 
> Writing an FCGI emulation layer for PSGI would allow you to run the
> FCGI wrapper from PSGI compatible web server - which does not make
> sense AT ALL!. It's even one more indirection.

Well, it would allow to run FastCGI application in *any* PSGI compatibile web server, including standalone (HTTP::Server::PSGI), mod_perl and Test::Plack 'server'.

Also even if wrapping FCGI application as PSGI application to run it on FCGI server doesn't make much sense on first glance, it neverheless allows to use many, many Plack::Middleware::*.

Mind you, I don't think that there are many FastCGI-only Perl web apps... if there are any.

I hope that clarify what I want (and no, I guess FCGI::Emulate::PSGI ain't it).

-- 
Jakub Narebski
Poland
Previous: Tatsuhiko MiyagawaNext: Tatsuhiko Miyagawa
Message 6 of 14 in “Re: gitweb, FastCGI and PSGI/Plack”
  1. Jakub NarebskiMay 9, 2010
  2. Tatsuhiko MiyagawaMay 10, 2010
  3. Jakub NarebskiMay 10, 2010
  4. Tatsuhiko MiyagawaMay 10, 2010
  5. Tatsuhiko MiyagawaMay 10, 2010
  6. Jakub NarebskiMay 10, 2010
  7. Tatsuhiko MiyagawaMay 10, 2010
  8. Jakub NarebskiMay 10, 2010
  9. Tatsuhiko MiyagawaMay 10, 2010
  10. Jakub NarebskiMay 10, 2010
  11. Tatsuhiko MiyagawaMay 11, 2010
  12. Jakub NarebskiMay 11, 2010
  13. Peter VereshaginMay 11, 2010
  14. Tatsuhiko MiyagawaMay 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.