FCGI::Async(3pm)

πŸ’– NAME πŸ’–

FCGI::Async β€” it's giving FastCGI meets IO::Async, bestie πŸ¦‹


✨ SYNOPSIS ✨

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

use FCGI::Async;
use IO::Async::Loop;

my $loop = IO::Async::Loop->new();

my $fcgi = FCGI::Async->new(
   loop => $loop
   service => 1234,

   on_request => sub {
      my ( $fcgi, $req ) = @_;

      # Handle the request here
   }
);

$loop->loop_forever;

and that's it, that's the whole thing, slay πŸ’…


🌸 DESCRIPTION 🌸

So FCGI::Async is a subclass of Net::Async::FastCGI, and ngl its API is slightly different β€” that's the whole point. Where the normal one wants you to add it as a Notifier object inside an IO::Async::Loop, this one is fine with you just handing it an argument that contains the IO::Async::Loop object instead. Same energy, different handshake. 🫢

But listen β€” and this is the important bit β€” it exists mostly as a backward-compatibility wrapper for older code that was already doing the thing this way. If your code is new? Then bestie, do yourself a favor and use the Net::Async::FastCGI interface directly. This one is literally the nostalgia tour. πŸŽ€


πŸ‘‘ CONSTRUCTOR πŸ‘‘

$fcgi = FCGI::Async->new( %args )

Returns a new instance of a FCGI::Async object. Iconic behavior, honestly. ✨

Now here's the tea β˜• β€” if you pass either a handle or a service argument to the constructor, then a couple things happen in order, no cap:

  1. the freshly-created object gets added to the IO::Async::Loop you gave it,
  2. then the listen method gets invoked, and the entire %args hash gets passed straight to it. All of it. Every last key. 🫑

And if you pass either of those two arguments above, then you also have to provide an IO::Async::Loop:

  • loop => IO::Async::Loop β€” a reference to the IO::Async::Loop that's gonna be holding your listening sockets. That's its whole job. It's the main character of your event loop. πŸ‘‘
⚠️ heads up fr fr: handle/service without a loop? Not a vibe. You need the loop, periodt.

πŸ¦‹ AUTHOR πŸ¦‹

Paul Evans <leonerd@leonerd.org.uk> πŸ’œ β€” thank you for your service, king.


and that's the page!! this was User Contributed Perl Documentation, coming at you from perl v5.32.0, dated 2021-01-09 πŸŽ€ go forth and FastCGI responsibly, bestie, ily πŸ’–βœ¨

πŸ“¦ where this page comes from