FastCGI::NativeCall::PSGI
FastCGI::NativeCall::PSGI
This is a PSGI interface for FastCGI::NativeCall
image https://github.com/jonathanstowe/raku-fcgi-psgi/workflows/CI/badge.svg not found
Synopsis
Basic usage:
use FastCGI::NativeCall::PSGI;
my $psgi = FastCGI::NativeCall::PSGI.new(path => "/tmp/fastcgi.sock", backlog => 32);
sub dispatch-psgi($env) {
return [ 200, { Content-Type => 'text/html' }, "Hello world" ];
}
$psgi.run(&dispatch-psgi);
Using Bailador:
use FastCGI::NativeCall::PSGI;
use Bailador;
get "/" => sub {
"Hello world";
}
my $psgi = FastCGI::NativeCall::PSGI.new(path => "/tmp/fastcgi.sock", backlog => 32);
$psgi.run(get-psgi-app());
Using Crust:
use FastCGI::NativeCall::PSGI;
use Crust::Builder;
my &app = builder {
mount "/" , sub (%env) {
start { 200, [Content-Type => "text/html"], ["Hello world"] };
}
};
my $psgi = FastCGI::NativeCall::PSGI.new(path => "/tmp/fastcgi.sock", backlog => 32);
$psgi.run(&app);
A suitable nginx configuration for these can be found in the examples directory.
If you are using Apache httpd with mod_fcgid then your script will be executed by the server with its STDIN (file descriptor 0) reopened to a listening socket that has already been created for you, in this case your constructor will become:
my $psgi = FastCGI::NativeCall::PSGI.new(sock => 0);
There is a snippet of Apache configuration in the examples directory. You will almost certainly want to tweak that to your own requirements.
Description
FastCGI is a protocol that allows an HTTP server to communicate with a persistent application over a socket, thus removing the process startup overhead of, say, traditional CGI applications. It is supported as standard (or through supporting modules,) by most common HTTP server software (such as Apache, nginx, lighthttpd and so forth.)
This module builds on FastCGI::NativeCall to provide a PSGI/P6GI/P6W interface for web applications.
Despite being single threaded it can be relatively high performance with appropriate tuning of the server configuration.
Installation
You will need an HTTP server that supports FastCGI to be able to use this.
Assuming you have a working Rakudo installation then you should be able to insall it with zef
zef install FastCGI::NativeCall::PSGI
# Or from a local clone
zef install .
Support
I am probably not the right person to be asking about the configuration of various server software to use FastCGI, you probably want to consult the manuals in the first place.
Some parts of the support for the full P6GI/P6W spec may be incomplete but this should be filled out over time.
In testing with Siege some frameworks performed remarkably worse than others, if you have a concern about the performance of your application please try to test with another host server as it may be the framework rather than this module.
Please send suggests/patches etc to github
Copyright and Licence
This is free software. Please see the LICENCE file for details.
Copyright (c) 2015, carlin <[email protected]>
Ā© 2017 - 2021 Jonathan Stowe