#!/usr/bin/perl
 
use strict;
use warnings;
 
use LWP::Socket;
use FCGI::ProcManager qw/ pm_manage pm_pre_dispatch pm_post_dispatch /;
 
# Prepare content and headers
my $content = join "", map { $_ } <DATA>;
my $headers ="HTTP/1.1 200 OK\r\n"
            . "Server: FlaresunsFakeServer/2009-09-10\r\n"
            . "Content-Type: text/html\r\n"
            . "Content-Length: " . length($content). "\r\n"
            . "Connection: close\r\n\r\n";
 
# Prepare and open socket
my $sock = new LWP::Socket();
$sock->bind('127.0.0.1', '8080');
$sock->listen(10);
 
# Create 5 childs
pm_manage(n_processes => 5);
 
while ( my $socket = $sock->accept(10) ) {
    pm_pre_dispatch();
    $socket->write($headers);
    $socket->write($content);
    $socket->shutdown();
    pm_post_dispatch();
}
 
$sock->shutdown();
 
__DATA__
<html>
<head><title>Hi</title></head>
<body>
    <h1>Hello from Habr!</h1>
</body>
</html>