Mojo::...FastCGI(3pm)

πŸ“¦
version 0.50 Β· 2 versions
  • 0.50 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.50 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Mojo::Server::FastCGI β€” the FastCGI Server page, but make it cute πŸ’–

okay bestie, welcome to the Mojo::...FastCGI(3pm) page from the User Contributed Perl Documentation πŸ’… this is where the FastCGI server lives, and we're gonna go through the whole thing together, no skips, no skimming, because you deserve the full lore 🌸


✨ NAME ✨

Mojo::Server::FastCGI β€” it's a FastCGI Server πŸ¦‹


✨ SYNOPSIS ✨

here's the whole vibe, copy-paste ready:

use Mojo::Server::FastCGI;

my $fcgi = Mojo::Server::FastCGI->new;
$fcgi->on_request(sub {
  my ($self, $tx) = @_;

  # Request
  my $method = $tx->req->method;
  my $path   = $tx->req->url->path;

  # Response
  $tx->res->code(200);
  $tx->res->headers->content_type('text/plain');
  $tx->res->body("$method request for $path!");

  # Resume transaction
  $tx->resume;
});
$fcgi->run;

like… the whole server is just vibes and one callback, we love that for us πŸ’–


✨ DESCRIPTION ✨

Mojo::Server::FastCGI is a portable pure-Perl FastCGI implementation ✨ exactly as described in the "FastCGI Specification". pure Perl, no weird native deps, we're thriving 🧚

and if you're like "okay but how do I actually deploy this bestie", go peek at Mojolicious::Guides::Cookbook β€” it's got the deployment recipes πŸ“


✨ ATTRIBUTES ✨

Mojo::Server::FastCGI inherits all attributes from Mojo::Server. yes, all of them, it's giving nepo baby but in the good way πŸ‘‘


✨ METHODS ✨

Mojo::Server::FastCGI inherits all methods from Mojo::Server, and then it implements these shiny new ones πŸ‘‡

accept_connection

my $c = $fcgi->accept_connection;

accepts a FastCGI connection 🫢 like come in, sit down, we've been expecting you

read_record

my ($type, $id, $body) = $fcgi->read_record($c);

parses a FastCGI record πŸ” three things come back: $type, $id, and $body

read_request

my $tx = $fcgi->read_request($c);

parses a FastCGI request 🌸 and hands you back a $tx

role_name

my $name = $fcgi->role_name(3);

gives you the FastCGI role name πŸ’«

role_number

my $number = $fcgi->role_number('FILTER');

gives you the FastCGI role number β€” feed it a name like 'FILTER', get the number πŸ”’

run

$fcgi->run;

starts FastCGI πŸš€ the main character moment, periodt

type_name

my $name = $fcgi->type_name(5);

gives you the FastCGI type name πŸ’œ

type_number

my $number = $fcgi->type_number('STDIN');

gives you the FastCGI type number β€” pass in something like 'STDIN', get the number πŸ”’

write_records

$fcgi->write_record($c, 'STDOUT', $id, 'HTTP/1.1 200 OK');

writes a FastCGI record ✍️ (yes, the heading says write_records and the call says write_record β€” that's just how the original rolls, we don't question the icon πŸ’€)

write_response

$fcgi->write_response($tx);

writes a FastCGI response πŸ’Œ


✨ DEBUGGING ✨

want the tea? β˜• set the MOJO_FASTCGI_DEBUG environment variable and you'll get some advanced diagnostics information sent to the Mojo logger as debug messages πŸ‘€

MOJO_FASTCGI_DEBUG=1

ngl this is the move when something's acting up and you need to see what's actually happening πŸ™ˆ


✨ SEE ALSO ✨


and that's the whole page bestie πŸŽ€ go forth and FastCGI responsibly πŸ’…

perl v5.34.0 Β· 2022-06-15 β€” mwah, love u, bye 🫢✨