AnyEvent::SCGI - Event based SCGI server
A simple Hello World SCGI server running on port 22222:
use AnyEvent::SCGI; use HTTP::Headers; my $s = scgi_server '127.0.0.1', 22222, sub { my $handle = shift; my $env = shift; my $content_ref = shift; # undef if none my $fatal_error = shift; my $error_string = shift; my $headers = HTTP::Headers->new( 'Status' => '200 OK', 'Content-Type' => 'text/plain', 'Connection' => 'close', ); $handle->push_write($headers->as_string . "\r\nHello World!\r\n"); $handle->push_shutdown; } AnyEvent->condvar->recv;
Sets up a SCGI server on the specified port. Can be used with or without Coro. You are responsible for any daemonization and startup code.
Coro
The usual AnyEvent callback caveats apply; make sure you don't block or re-enter the event loop in a way that's not supported. This module has been tested for use with Coro, but if you don't want to use that, it's recommended that you return from the callback as quickly as possible.
AnyEvent
If you're using Coro, here's the supported calling pattern:
use Coro; use Coro::AnyEvent; use AnyEvent; use AnyEvent::SCGI; my $s = scgi_server $server_name, $port, sub { my $handle = shift; my $env = shift; my $content = shift; # handle errors if any async { my $stuff = expensive($content); $handle->push_write( $headers->as_string . "\r\nHello World!\r\n$stuff" ); $handle->push_shutdown; }; # return before running async block }; AE::cv->recv;
This function creates a TCP socket on the given host and port by calling tcp_server() from AnyEvent::Socket.
tcp_server()
AnyEvent::Socket
Calls $handler_cb when a valid SCGI request has been received. The callback will block other clients until it returns.
$handler_cb
The first parameter is the AnyEvent::Handle If the request has a payload, a reference to it is passed in as the $content parameter.
AnyEvent::Handle
$content
On error, \%env and \$content are undef and the usual $fatal and $error parameters are passed in as subsequent arguments. On "EOF" from the client, fatal is "0" and error is 'EOF'.
\%env
\$content
$fatal
$error
Jeremy Stashewsky <stash@cpan.org>
Kevin Jones <kevinj@cpan.org>
Please report any bugs or feature requests to bug-anyevent-scgi at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-SCGI. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-anyevent-scgi at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc AnyEvent::SCGI
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-SCGI
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/AnyEvent-SCGI
CPAN Ratings
http://cpanratings.perl.org/d/AnyEvent-SCGI
Search CPAN
http://search.cpan.org/dist/AnyEvent-SCGI
Copyright 2009 Jeremy Stashewsky Copyright 2009 Kevin Jones
Copyright 2009 Socialtext Inc., all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install AnyEvent::SCGI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::SCGI
CPAN shell
perl -MCPAN -e shell install AnyEvent::SCGI
For more information on module installation, please visit the detailed CPAN module installation guide.