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.
In reply to Re^6: Stopping an HTTP::Server::Simple server
by textual
in thread Stopping an HTTP::Server::Simple server
by jaldhar
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |