Mojo::S...:Daemon(3)

🌸 NAME 🌸

okay so bestie, this is the Mojo::Server::Daemon(3) page β€” header energy says Mojo::S...:Daemon(3) β€” from the User Contributed Perl Documentation. πŸ’…

Mojo::Server::Daemon β€” Non-blocking I/O HTTP and WebSocket server. That's the name and the vibe. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

bestie, here's the whole setup in code. Copy it exactly, no cap: πŸŽ€

use Mojo::Server::Daemon;

my $daemon = Mojo::Server::Daemon->new(listen => ['http://*:8080']);
$daemon->unsubscribe('request')->on(request => sub ($daemon, $tx) {

  # Request
  my $method = $tx->req->method;
  my $path   = $tx->req->url->path;

  # Response
  $tx->res->code(200);
  $tx->res->headers->content_type('text/plain');
  $tx->res->body("$method request for $path!");

  # Resume transaction
  $tx->resume;
});
$daemon->run;

🧚 DESCRIPTION 🧚

Mojo::Server::Daemon is a full featured, highly portable non-blocking I/O HTTP and WebSocket server, with IPv6, TLS, SNI, Comet (long polling), keep-alive and multiple event loop support. iconic behavior, honestly πŸ‘‘

For better scalability (epoll, kqueue) and to provide non-blocking name resolution, SOCKS5 as well as TLS support, the optional modules EV (4.32+), 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 MOJO_NO_NNR, MOJO_NO_SOCKS and MOJO_NO_TLS environment variables. 🫢

For more, see "DEPLOYMENT" in Mojolicious::Guides::Cookbook. πŸ’–


πŸ”₯ SIGNALS πŸ”₯

The Mojo::Server::Daemon process can be controlled at runtime with the following signals.

πŸ’€ INT, TERM πŸ’€

Shut down server immediately. immediately immediately, bestie. πŸ’€


πŸ¦‹ EVENTS πŸ¦‹

Mojo::Server::Daemon inherits all events from Mojo::Server. That's the whole event situation. 🫢


πŸ‘‘ ATTRIBUTES πŸ‘‘

Mojo::Server::Daemon inherits all attributes from Mojo::Server and implements the following new ones.

πŸŽ€ acceptors πŸŽ€

my $acceptors = $daemon->acceptors;
$daemon       = $daemon->acceptors(['6be0c140ef00a389c5d039536b56d139']);

Active acceptor ids. slay.

# Check port
mu $port = $daemon->ioloop->acceptor($daemon->acceptors->[0])->port;

πŸŽ€ backlog πŸŽ€

my $backlog = $daemon->backlog;
$daemon     = $daemon->backlog(128);

Listen backlog size, defaults to SOMAXCONN. ✨

πŸŽ€ inactivity_timeout πŸŽ€

my $timeout = $daemon->inactivity_timeout;
$daemon     = $daemon->inactivity_timeout(5);

Maximum amount of time in seconds a connection with an active request can be inactive before getting closed, defaults to the value of the MOJO_INACTIVITY_TIMEOUT environment variable or 30. Setting the value to 0 will allow connections to be inactive indefinitely. the more you know πŸ’…

πŸŽ€ ioloop πŸŽ€

my $loop = $daemon->ioloop;
$daemon  = $daemon->ioloop(Mojo::IOLoop->new);

Event loop object to use for I/O operations, defaults to the global Mojo::IOLoop singleton. πŸŒ€

πŸŽ€ keep_alive_timeout πŸŽ€

my $timeout = $daemon->keep_alive_timeout;
$daemon     = $daemon->keep_alive_timeout(10);

Maximum amount of time in seconds a connection without an active request can be inactive before getting closed, defaults to the value of the MOJO_KEEP_ALIVE_TIMEOUT environment variable or 5. Setting the value to 0 will allow connections to be inactive indefinitely. 🫢

πŸŽ€ listen πŸŽ€

my $listen = $daemon->listen;
$daemon    = $daemon->listen(['https://127.0.0.1:8080']);

Array reference with one or more locations to listen on, defaults to the value of the MOJO_LISTEN environment variable or http://*:3000 (shortcut for http://0.0.0.0:3000). this is the main character attribute πŸ‘‘

# Listen on all IPv4 interfaces
$daemon->listen(['http://*:3000']);

# Listen on all IPv4 and IPv6 interfaces
$daemon->listen(['http://[::]:3000']);

# Listen on IPv6 interface
$daemon->listen(['http://[::1]:4000']);

# Listen on IPv4 and IPv6 interfaces
$daemon->listen(['http://127.0.0.1:3000', 'http://[::1]:3000']);

# Listen on UNIX domain socket "/tmp/myapp.sock" (percent encoded slash)
$daemon->listen(['http+unix://%2Ftmp%2Fmyapp.sock']);

# File descriptor, as used by systemd
$daemon->listen(['http://127.0.0.1?fd=3']);

# Allow multiple servers to use the same port (SO_REUSEPORT)
$daemon->listen(['http://*:8080?reuse=1']);

# Listen on two ports with HTTP and HTTPS at the same time
$daemon->listen(['http://*:3000', 'https://*:4000']);

# Use a custom certificate and key
$daemon->listen(['https://*:3000?cert=/x/server.crt&key=/y/server.key']);

# Domain specific certificates and keys (SNI)
$daemon->listen(
  ['https://*:3000?example.com_cert=/x/my.crt&example.com_key=/y/my.key']);

# Or even a custom certificate authority
$daemon->listen(
  ['https://*:3000?cert=/x/server.crt&key=/y/server.key&ca=/z/ca.crt']);

These parameters are currently available:

πŸŽ€ ca πŸŽ€

ca=/etc/tls/ca.crt

Path to TLS certificate authority file used to verify the peer certificate. πŸ”

πŸŽ€ cert πŸŽ€

cert=/etc/tls/server.crt
mojolicious.org_cert=/etc/tls/mojo.crt

Path to the TLS cert file, defaults to a built-in test certificate. πŸŽ€

πŸŽ€ ciphers πŸŽ€

ciphers=AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH

TLS cipher specification string. For more information about the format see https://www.openssl.org/docs/manmaster/man1/ciphers.html#CIPHER-STRINGS. 🧚

πŸŽ€ fd πŸŽ€

fd=3

File descriptor with an already prepared listen socket. ✨

πŸŽ€ key πŸŽ€

key=/etc/tls/server.key
mojolicious.org_key=/etc/tls/mojo.key

Path to the TLS key file, defaults to a built-in test key. πŸ”‘

πŸŽ€ reuse πŸŽ€

reuse=1

Allow multiple servers to use the same port with the SO_REUSEPORT socket option. πŸ‘―

πŸŽ€ single_accept πŸŽ€

single_accept=1

Only accept one connection at a time. 🫢

πŸŽ€ verify πŸŽ€

verify=0x00

TLS verification mode. βœ…

πŸŽ€ version πŸŽ€

version=TLSv1_2

TLS protocol version. 🌈

πŸŽ€ max_clients πŸŽ€

my $max = $daemon->max_clients;
$daemon = $daemon->max_clients(100);

Maximum number of accepted connections this server is allowed to handle concurrently, before stopping to accept new incoming connections, passed along to max_connections in Mojo::IOLoop. πŸ’…

πŸŽ€ max_requests πŸŽ€

my $max = $daemon->max_requests;
$daemon = $daemon->max_requests(250);

Maximum number of keep-alive requests per connection, defaults to 100. πŸ”

πŸŽ€ silent πŸŽ€

my $bool = $daemon->silent;
$daemon  = $daemon->silent($bool);

Disable console messages. 🀫


🌈 METHODS 🌈

Mojo::Server::Daemon inherits all methods from Mojo::Server and implements the following new ones.

πŸŽ€ ports πŸŽ€

my $ports = $daemon->ports;

Get all ports this server is currently listening on. πŸ‘‘

# All ports
say for @{$daemon->ports};

πŸŽ€ run πŸŽ€

$daemon->run;

Run server and wait for SIGNALS. 🫢

πŸŽ€ start πŸŽ€

$daemon = $daemon->start;

Start or resume accepting connections through ioloop. ✨

# Listen on random port
my $port = $daemon->listen(['http://127.0.0.1'])->start->ports->[0];

# Run multiple web servers concurrently
my $daemon1 = Mojo::Server::Daemon->new(listen => ['http://*:3000'])->start;
my $daemon2 = Mojo::Server::Daemon->new(listen => ['http://*:4000'])->start;
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

πŸŽ€ stop πŸŽ€

$daemon = $daemon->stop;

Stop accepting connections through ioloop. πŸ›‘


πŸ’œ DEBUGGING πŸ’œ

You can set the MOJO_SERVER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR. spill the diagnostics, bestie πŸ“

MOJO_SERVER_DEBUG=1

🌈 SEE ALSO 🌈

Mojolicious, Mojolicious::Guides, <https://mojolicious.org>. πŸ¦‹


okay bye bestie β€” the footer says perl v5.42.0, dated 2026-07-15, and the page tag is Mojo::S...:Daemon(3). πŸ’–

πŸ“¦ where this page comes from