Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A SCGI library for Perl 6
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


SCGI for Perl 6

This is a simple SCGI library for Perl 6.



   SCGI version 2.0 is coming soon. It will be refactored to use a class
   structure similar to my new FastCGI library, and will break compatibility
   with 1.0 in the following ways:

     1.) PSGI mode will be on by default (use of Raw mode is discouraged.)
     2.) 'SCGI.Body' and 'SCGI.SCGI' are gone.
     3.) 'SCGI.Object' is renamed 'scgi.request'.
     4.) Request object has access to connection and SCGI objects.
   All in all, it will be more flexible, and easier to use, but any libraries
   and projects using it will have to be updated to take the above changes
   into account. Hopefully everyone is already using PSGI, and nobody is
   using the SCGI.* variables directly.

   The rest of this README applies to the current 1.0 version.


It's main influences are the Perl 5 SCGI library, and the
Perl 6 HTTP::Daemon library.

It offers a bit of candy coating compared to the Perl 5 version.

It also offers an optional (but recommended) PSGI interface.

The environment contains three special keys:

  SCGI.Body is the request body (usually from an HTTP POST.)
  SCGI.Object is a reference to the individual request object.
  SCGI.SCGI is a reference to the SCGI object itself.

If you use the PSGI setting, the standard PSGI variables will be added
to the environment too.

Also, you don't need to create your own IO::Socket::INET object.
Just pass an 'addr' and 'port' attribute to the new() declaration and it'll
create the object for you.

Oh yeah, and instead of using the while loop as shown on the Perl 5 SCGI
documentation, there is a convenience method called 'handle' that does
the heavy lifting for you:

  use SCGI;

  my $scgi = :addr<localhost>, :port(8080), :PSGI );

  my $handler = sub (%env) {
    my $name = %env<QUERY_STRING> // 'world';
    my $status = '200';
    my @headers = [ 'Content-Type' => 'text/plain' ];
    my @body = [ "Hello $name\n" ];
    return [ $status, @headers, @body ];

  $scgi.handle: $handler;

If you are not using the PSGI interface, the output of the handler will be 
sent as the SCGI response, so make sure it is a valid CGI response!

** Apache configuration:

*** If using mod_scgi:

Add the following line to your site config, changing the details to match your
SCGI script configuration:

  SCGIMount /scgi/

*** If using mod_proxy_scgi:

Add the following line to your site config, changes the details to match your
SCGI script configuration:

  <Proxy *>
    Order deny,allow
    Allow from all
  ProxyPass /scgi/ scgi://localhost:8118/

*** Apache redirect rules

Regardless of whether you are using mod_scgi or mod_proxy_scgi, you can
use the following steps to redirect non-exitent pages to your SCGI script.

Add the following lines either after the above statement, or in an
.htaccess file in your website root:

  RewriteEngine On

  ## Add additional rules before the following!
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ /scgi/$1 [QSA,L,PT]

That's it. Now any path that doesn't match an existing file in your
web root, will be redirected to your SCGI script.

Similar tricks are available for other web servers, but I haven't tested
them, so have not documented them. A quick Google search for SCGI should
turn up a multitude of howto documents.

** Requirements:

 * Rakudo Perl 6  <>
 * HTTP::Status   <>

Author: Timothy Totten (supernovus) <>

Released under the Artisitc License 2.0

Something went wrong with that request. Please try again.