in reply to Re^5: Stopping an HTTP::Server::Simple server
in thread Stopping an HTTP::Server::Simple server
Sorry, my previous answer was ambiguous: $pid is undefined in the handle_request () method of MyWebServer, but it is correctly set to something like "-1470" in test.pl.
In fact, writing this in test.pl effectively stops the server immediately:use strict; use warnings; use MyWebServer; my $server = MyWebServer->new(8080); my $pid = $server->background(); kill 9, $pid;
But in order to execute this instruction in response to some HTTP request, (I think) I need to call it from within a handler in MyWebServer.
I find that the following:effectively stops the server if it is added anywhere in MyWebServer.pm's "body" (e.g. at the first line), but not if it is added in the handle_request() method.kill 9, $$;
I've also tried tilly's suggestion to have test.pl write the PID in a file, then have handle_request() read this file. It does succeed at passing the PID, and I do not get the "Can't kill a non-numeric process ID" message anymore, however the call to kill does not stop the server in this case.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: Stopping an HTTP::Server::Simple server
by tilly (Archbishop) on Jan 26, 2011 at 16:56 UTC | |
by textual (Novice) on Jan 26, 2011 at 17:28 UTC | |
Re^7: Stopping an HTTP::Server::Simple server
by Corion (Patriarch) on Jan 26, 2011 at 16:43 UTC |