Helter has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a deamon in perl that will be running on my home machine 24/7. I would like to be able to configure it from anywhere I can access the internet.

I know I could configure Apache to do this, but since I only want to serve 2 or 3 pages, I am looking for a much more lightweight solution. Ideally it would be a perl script running, listening on port 80 and responding to requests using HTTP.

Eventually this would be incorporated into my deamon to configure it at will.

I have searched CPAN and found Net::Server, but it seems to be at a lower level than what I am looking for.

Suggestions?

Replies are listed 'Best First'.
Re: A simple web interface?
by metlhed_ (Beadle) on Aug 30, 2002 at 15:13 UTC

    You should check out HTTP::Daemon from CPAN. And here are a couple Web Techniques columns that should be what your looking for. Col23 and Col24.

Re: A simple web interface?
by {NULE} (Hermit) on Aug 31, 2002 at 02:59 UTC
Re: A simple web interface?
by rcaputo (Chaplain) on Aug 31, 2002 at 20:26 UTC

    This was an interesting problem, so I put together a program that is both a telnet chat server and an HTTP server. The HTTP server returns a log of recent chatter on the telnet server.

    #!/usr/bin/perl use warnings; use strict; use CGI qw(:standard); # For HTML building functions. use POE; use POE::Component::Server::HTTP; # For the web interface. use POE::Component::Server::TCP; # For the telnet interface. sub MAX_LOG_LENGTH () { 50 } my @chat_log; ### Start the web server. POE::Component::Server::HTTP->new ( Port => 32080, ContentHandler => { "/" => \&web_handler }, Headers => { Server => 'See http://poe.perl.org/?POE_Cookbo +ok' }, ); ### Start the chat server. POE::Component::Server::TCP->new ( Alias => "chat_server", Port => 32081, InlineStates => { send => \&handle_send }, ClientConnected => \&client_connected, ClientError => \&client_error, ClientDisconnected => \&client_disconnected, ClientInput => \&client_input, ); ### Run the servers together, and exit when they are done. $poe_kernel->run(); exit 0; ### Handlers for the web server. These functions are commented at ### http://poe.perl.org/?POE_Cookbook/Web_Server_With_Components sub web_handler { my ( $request, $response ) = @_; # Build the response. $response->code(RC_OK); $response->push_header( "Content-Type", "text/html" ); my $count = @chat_log; my $content = start_html("Last $count messages.") . h1("Last $count messages." +); if ($count) { $content .= ul( li( \@chat_log ) ); } else { $content .= p("Nothing has been said yet."); } $content .= end_html(); $response->content($content); # Signal that the request was handled okay. return RC_OK; } ### Handlers for the chat server. These functions are commented at ### http://poe.perl.org/?POE_Cookbook/Chat_Server my %users; sub broadcast { my ( $sender, $message ) = @_; # Log it for the web. This is the only part that's different from # the basic chat server. push @chat_log, "$sender $message"; shift @chat_log if @chat_log > MAX_LOG_LENGTH; # Send it to everyone. foreach my $user ( keys %users ) { if ( $user == $sender ) { $poe_kernel->post( $user => send => "You $message" ); } else { $poe_kernel->post( $user => send => "$sender $message" ); } } } sub handle_send { my ( $heap, $message ) = @_[ HEAP, ARG0 ]; $heap->{client}->put($message); } sub client_connected { my $session_id = $_[SESSION]->ID; $users{$session_id} = 1; broadcast( $session_id, "connected." ); } sub client_disconnected { my $session_id = $_[SESSION]->ID; delete $users{$session_id}; broadcast( $session_id, "disconnected." ); } sub client_error { my $session_id = $_[SESSION]->ID; delete $users{$session_id}; broadcast( $session_id, "disconnected." ); $_[KERNEL]->yield("shutdown"); } sub client_input { my ( $session, $input ) = @_[ KERNEL, SESSION, ARG0 ]; broadcast( $session->ID, "said: $input" ); }