Sample Minimal FastCGI Applications

In Perl
use FCGI;
 
my $count = 0;
my $request = FCGI::Request();
 
while ($request->Accept >= 0) {
	print('Content-type: text/html', "\r\n\r\n");
	print 'Count: ', $count++);
}

Note: warn() or die() will not produce any output in your error log, unless you explicitely request it like so:
$warn_handler = sub { print STDERR @_ };
$die_handler = sub { print STDERR @_ unless $^S };

$SIG{__WARN__} = $warn_handler if (tied (*STDIN));
$SIG{__DIE__} = $die_handler if (tied (*STDIN));
In C
#include "fcgi_stdio.h"
#include <stdlib.h>
 
int
main(int argc, char *argv)
{
	int count = 0;
	
	while (FCGI_Accept() >= 0) {
		printf("Content-type: text/html\r\n\r\n"
		       "Request: %d on host %s", count++,
		       getenv("SERVER_NAME"));
	}
	return (0);
}

You can compile this using:

  $ cc -I/usr/local/include -o foo foo.c -L/usr/local/lib -lfcgi

For more complex applications, you may be interested in our PerCGI tookit.


Csoft.net
© 2024 CubeSoft Communications
All Rights Reserved.