.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Server::Daemon 3pm" .TH Mojo::Server::Daemon 3pm "2019-02-05" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Server::Daemon \- Non\-blocking I/O HTTP and WebSocket server .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Server::Daemon; \& \& my $daemon = Mojo::Server::Daemon\->new(listen => [\*(Aqhttp://*:8080\*(Aq]); \& $daemon\->unsubscribe(\*(Aqrequest\*(Aq)\->on(request => sub { \& my ($daemon, $tx) = @_; \& \& # Request \& my $method = $tx\->req\->method; \& my $path = $tx\->req\->url\->path; \& \& # Response \& $tx\->res\->code(200); \& $tx\->res\->headers\->content_type(\*(Aqtext/plain\*(Aq); \& $tx\->res\->body("$method request for $path!"); \& \& # Resume transaction \& $tx\->resume; \& }); \& $daemon\->run; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Server::Daemon is a full featured, highly portable non-blocking I/O \&\s-1HTTP\s0 and WebSocket server, with IPv6, \s-1TLS, SNI,\s0 Comet (long polling), keep-alive and multiple event loop support. .PP For better scalability (epoll, kqueue) and to provide non-blocking name resolution, \s-1SOCKS5\s0 as well as \s-1TLS\s0 support, the optional modules \s-1EV\s0 (4.0+), Net::DNS::Native (0.15+), IO::Socket::Socks (0.64+) and IO::Socket::SSL (2.009+) will be used automatically if possible. Individual features can also be disabled with the \f(CW\*(C`MOJO_NO_NNR\*(C'\fR, \f(CW\*(C`MOJO_NO_SOCKS\*(C'\fR and \&\f(CW\*(C`MOJO_NO_TLS\*(C'\fR environment variables. .PP See \*(L"\s-1DEPLOYMENT\*(R"\s0 in Mojolicious::Guides::Cookbook for more. .SH "SIGNALS" .IX Header "SIGNALS" The Mojo::Server::Daemon process can be controlled at runtime with the following signals. .SS "\s-1INT, TERM\s0" .IX Subsection "INT, TERM" Shut down server immediately. .SH "EVENTS" .IX Header "EVENTS" Mojo::Server::Daemon inherits all events from Mojo::Server. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::Server::Daemon inherits all attributes from Mojo::Server and implements the following new ones. .SS "acceptors" .IX Subsection "acceptors" .Vb 2 \& my $acceptors = $daemon\->acceptors; \& $daemon = $daemon\->acceptors([\*(Aq6be0c140ef00a389c5d039536b56d139\*(Aq]); .Ve .PP Active acceptor ids. .PP .Vb 2 \& # Check port \& mu $port = $daemon\->ioloop\->acceptor($daemon\->acceptors\->[0])\->port; .Ve .SS "backlog" .IX Subsection "backlog" .Vb 2 \& my $backlog = $daemon\->backlog; \& $daemon = $daemon\->backlog(128); .Ve .PP Listen backlog size, defaults to \f(CW\*(C`SOMAXCONN\*(C'\fR. .SS "inactivity_timeout" .IX Subsection "inactivity_timeout" .Vb 2 \& my $timeout = $daemon\->inactivity_timeout; \& $daemon = $daemon\->inactivity_timeout(5); .Ve .PP Maximum amount of time in seconds a connection can be inactive before getting closed, defaults to the value of the \f(CW\*(C`MOJO_INACTIVITY_TIMEOUT\*(C'\fR environment variable or \f(CW15\fR. Setting the value to \f(CW0\fR will allow connections to be inactive indefinitely. .SS "ioloop" .IX Subsection "ioloop" .Vb 2 \& my $loop = $daemon\->ioloop; \& $daemon = $daemon\->ioloop(Mojo::IOLoop\->new); .Ve .PP Event loop object to use for I/O operations, defaults to the global Mojo::IOLoop singleton. .SS "listen" .IX Subsection "listen" .Vb 2 \& my $listen = $daemon\->listen; \& $daemon = $daemon\->listen([\*(Aqhttps://127.0.0.1:8080\*(Aq]); .Ve .PP Array reference with one or more locations to listen on, defaults to the value of the \f(CW\*(C`MOJO_LISTEN\*(C'\fR environment variable or \f(CW\*(C`http://*:3000\*(C'\fR (shortcut for \&\f(CW\*(C`http://0.0.0.0:3000\*(C'\fR). .PP .Vb 2 \& # Listen on all IPv4 interfaces \& $daemon\->listen([\*(Aqhttp://*:3000\*(Aq]); \& \& # Listen on all IPv4 and IPv6 interfaces \& $daemon\->listen([\*(Aqhttp://[::]:3000\*(Aq]); \& \& # Listen on IPv6 interface \& $daemon\->listen([\*(Aqhttp://[::1]:4000\*(Aq]); \& \& # Listen on IPv4 and IPv6 interfaces \& $daemon\->listen([\*(Aqhttp://127.0.0.1:3000\*(Aq, \*(Aqhttp://[::1]:3000\*(Aq]); \& \& # Listen on UNIX domain socket "/tmp/myapp.sock" (percent encoded slash) \& $daemon\->listen([\*(Aqhttp+unix://%2Ftmp%2Fmyapp.sock\*(Aq]); \& \& # File descriptor, as used by systemd \& $daemon\->listen([\*(Aqhttp://127.0.0.1?fd=3\*(Aq]); \& \& # Allow multiple servers to use the same port (SO_REUSEPORT) \& $daemon\->listen([\*(Aqhttp://*:8080?reuse=1\*(Aq]); \& \& # Listen on two ports with HTTP and HTTPS at the same time \& $daemon\->listen([\*(Aqhttp://*:3000\*(Aq, \*(Aqhttps://*:4000\*(Aq]); \& \& # Use a custom certificate and key \& $daemon\->listen([\*(Aqhttps://*:3000?cert=/x/server.crt&key=/y/server.key\*(Aq]); \& \& # Domain specific certificates and keys (SNI) \& $daemon\->listen( \& [\*(Aqhttps://*:3000?example.com_cert=/x/my.crt&example.com_key=/y/my.key\*(Aq]); \& \& # Or even a custom certificate authority \& $daemon\->listen( \& [\*(Aqhttps://*:3000?cert=/x/server.crt&key=/y/server.key&ca=/z/ca.crt\*(Aq]); .Ve .PP These parameters are currently available: .IP "ca" 2 .IX Item "ca" .Vb 1 \& ca=/etc/tls/ca.crt .Ve .Sp Path to \s-1TLS\s0 certificate authority file used to verify the peer certificate. .IP "cert" 2 .IX Item "cert" .Vb 2 \& cert=/etc/tls/server.crt \& mojolicious.org_cert=/etc/tls/mojo.crt .Ve .Sp Path to the \s-1TLS\s0 cert file, defaults to a built-in test certificate. .IP "ciphers" 2 .IX Item "ciphers" .Vb 1 \& ciphers=AES128\-GCM\-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH .Ve .Sp \&\s-1TLS\s0 cipher specification string. For more information about the format see . .IP "fd" 2 .IX Item "fd" .Vb 1 \& fd=3 .Ve .Sp File descriptor with an already prepared listen socket. .IP "key" 2 .IX Item "key" .Vb 2 \& key=/etc/tls/server.key \& mojolicious.org_key=/etc/tls/mojo.key .Ve .Sp Path to the \s-1TLS\s0 key file, defaults to a built-in test key. .IP "reuse" 2 .IX Item "reuse" .Vb 1 \& reuse=1 .Ve .Sp Allow multiple servers to use the same port with the \f(CW\*(C`SO_REUSEPORT\*(C'\fR socket option. .IP "single_accept" 2 .IX Item "single_accept" .Vb 1 \& single_accept=1 .Ve .Sp Only accept one connection at a time. .IP "verify" 2 .IX Item "verify" .Vb 1 \& verify=0x00 .Ve .Sp \&\s-1TLS\s0 verification mode. .IP "version" 2 .IX Item "version" .Vb 1 \& version=TLSv1_2 .Ve .Sp \&\s-1TLS\s0 protocol version. .SS "max_clients" .IX Subsection "max_clients" .Vb 2 \& my $max = $daemon\->max_clients; \& $daemon = $daemon\->max_clients(100); .Ve .PP Maximum number of accepted connections this server is allowed to handle concurrently, before stopping to accept new incoming connections, passed along to \*(L"max_connections\*(R" in Mojo::IOLoop. .SS "max_requests" .IX Subsection "max_requests" .Vb 2 \& my $max = $daemon\->max_requests; \& $daemon = $daemon\->max_requests(250); .Ve .PP Maximum number of keep-alive requests per connection, defaults to \f(CW100\fR. .SS "silent" .IX Subsection "silent" .Vb 2 \& my $bool = $daemon\->silent; \& $daemon = $daemon\->silent($bool); .Ve .PP Disable console messages. .SH "METHODS" .IX Header "METHODS" Mojo::Server::Daemon inherits all methods from Mojo::Server and implements the following new ones. .SS "ports" .IX Subsection "ports" .Vb 1 \& my $ports = $daemon\->ports; .Ve .PP Get all ports this server is currently listening on. .PP .Vb 2 \& # All ports \& say for @{$daemon\->ports}; .Ve .SS "run" .IX Subsection "run" .Vb 1 \& $daemon\->run; .Ve .PP Run server and wait for \*(L"\s-1SIGNALS\*(R"\s0. .SS "start" .IX Subsection "start" .Vb 1 \& $daemon = $daemon\->start; .Ve .PP Start or resume accepting connections through \*(L"ioloop\*(R". .PP .Vb 2 \& # Listen on random port \& my $port = $daemon\->listen([\*(Aqhttp://127.0.0.1\*(Aq])\->start\->ports\->[0]; \& \& # Run multiple web servers concurrently \& my $daemon1 = Mojo::Server::Daemon\->new(listen => [\*(Aqhttp://*:3000\*(Aq])\->start; \& my $daemon2 = Mojo::Server::Daemon\->new(listen => [\*(Aqhttp://*:4000\*(Aq])\->start; \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SS "stop" .IX Subsection "stop" .Vb 1 \& $daemon = $daemon\->stop; .Ve .PP Stop accepting connections through \*(L"ioloop\*(R". .SH "DEBUGGING" .IX Header "DEBUGGING" You can set the \f(CW\*(C`MOJO_SERVER_DEBUG\*(C'\fR environment variable to get some advanced diagnostics information printed to \f(CW\*(C`STDERR\*(C'\fR. .PP .Vb 1 \& MOJO_SERVER_DEBUG=1 .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .