Skip to content

[limits]

[limits] sets the limits that each request starts with. [limits.hard] sets the highest value that a request may raise each limit to, with Core\Config::set.

The main keys are memory, cpu_time, wall_time, max_tasks, max_output and max_regex_steps. cpu_time counts only computing time. wall_time counts waiting too. When [limits.hard] does not set a key, a program can lower that limit but cannot raise it. A program you start from the command line may raise its memory limit to any value, unless [limits.hard] sets memory.

By default, memory is 128M and a request has 30s of cpu_time. nvs run and nvs test have no cpu_time limit unless you set one. false removes a limit.

When a request reaches a limit, Novis stops it. This is not an exception, so catch does not catch it. The function given to Core\Fatal::onLimit runs, and nvs run exits with status 1.

Good to know: in this version, nvs run enforces memory and cpu_time. It does not stop a program that exceeds wall_time, max_tasks or max_output.

Examples

The examples below run with this configuration file.

nvs.toml
# A request starts with 32M of memory.
# The program may raise that to 128M, and no higher.
# `max_tasks` has no line in `[limits.hard]`, so a program may not raise it above 8.
[limits]
memory = "32M"
max_tasks = 8
[limits.hard]
memory = "128M"

More memory for one large report

<?nvs
// Shows how a program raises its own memory limit for one large job, up to the highest limit.
// 128M is the highest limit in `[limits.hard]`. So this prints `yes`.
echo Core\Config::set('memory', '128M') ? 'yes' : 'no', "\n";
// 129M is above the highest limit. The call returns `false`, so this prints `no`.
echo Core\Config::set('memory', '129M') ? 'yes' : 'no', "\n";
echo Core\Config::get('memory'), "\n";
// The report needs 64M of text. That is more than 32M, and it now works. This prints `67108864`.
string $report = Core\Str::repeat('x', 67108864);
echo Core\Str::length($report), "\n";
// `[limits.hard]` has no `max_tasks`, so the highest limit is the starting value, 8.
// The program can lower it to 4, so this prints `yes`.
echo Core\Config::set('max_tasks', '4') ? 'yes' : 'no', "\n";
// The program cannot raise it above 8, so this prints `no`.
echo Core\Config::set('max_tasks', '1000') ? 'yes' : 'no', "\n";
Output
yes
no
128M
67108864
yes
no

limits

[limits] sets the limits that one request or one script starts with. They include the memory it may use and the CPU time it may spend. They also include the wall time (time on the clock) and the bytes it may send.

When [limits] does not set memory, every program may use 128M. When it does not set cpu_time, a request, a connection, a scheduled script and a queued job may use 30s. nvs run and nvs test have no cpu_time limit unless you set one. false removes a limit.

A program can lower most of its limits with Core\Config::set. Use this to stop a program early when it uses too much.

On a server, a program can raise a limit only up to the ceiling in [limits.hard]. When [limits.hard] does not set a key, the ceiling is the value in [limits]. For a value over the ceiling, set returns false, and the old value stays. A program you start from the command line may raise its memory limit to any value, unless [limits.hard] sets memory. A few keys in this block can be set only in the file, and their own pages say so.

A request may change these keys in this block with Core\Config::set: memory, cpu_time, wall_time, max_output, request_body, upload_total, max_multipart_parts, max_tasks, max_regex_steps. Only nvs.toml sets the others.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# Every request starts with 256M of memory. A program may raise its own limit up to 512M.
[limits]
memory = "256M"
[limits.hard]
memory = "512M"

What a request starts with and may change

<?nvs
// `[limits]` sets the limits each request starts with. They cover memory, CPU
// time, wall time and the size of the response. A program can read its own limits.
echo 'memory to start with: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
echo 'the ceiling above it: ', Core\Config::get('limits.hard.memory') ?? '(unset)', "\n";
// A program may lower its own limit. The new limit applies to the rest of
// the request, and the request stops if it uses more.
echo 'ask for less: ', Core\Config::set('limits.memory', '64M') ? 'accepted' : 'not allowed', "\n";
echo 'in force now: ', Core\Config::get('limits.memory'), "\n";
// A program may also raise it, up to the ceiling in `[limits.hard]`. A value over
// the ceiling returns `false`, and the previous value stays in force.
echo 'ask for 400M: ', Core\Config::set('limits.memory', '400M') ? 'accepted' : 'not allowed', "\n";
echo 'ask for 1G: ', Core\Config::set('limits.memory', '1G') ? 'accepted' : 'not allowed', "\n";
echo 'in force now: ', Core\Config::get('limits.memory'), "\n";
// `Core\Config::set('limits.hard.memory', ...)` does not compile,
// because a program may not change `limits.hard.memory`.
// This program keeps the name in a variable. The compiler does not check a variable, so `set` runs and returns `false`.
string $ceiling = 'limits.hard.memory';
echo 'raise the ceiling: ', Core\Config::set($ceiling, '1G') ? 'accepted' : 'not allowed', "\n";
// `limits.cpu_time` is not set here, so it is `null`. Under `nvs run` there is
// then no CPU time limit. A program can still set one for itself.
echo 'cpu time to start: ', Core\Config::get('limits.cpu_time') ?? '(not set)', "\n";
echo 'bound my own cpu: ', Core\Config::set('limits.cpu_time', '2s') ? 'accepted' : 'not allowed', "\n";
// `Core\Config::restore` sets the key back to the value in the configuration
// file. Here that is `256M`.
Core\Config::restore('limits.memory');
echo 'back to the file: ', Core\Config::get('limits.memory'), "\n";
Output
memory to start with: 256M
the ceiling above it: 512M
ask for less: accepted
in force now: 64M
ask for 400M: accepted
ask for 1G: not allowed
in force now: 400M
raise the ceiling: not allowed
cpu time to start: (not set)
bound my own cpu: accepted
back to the file: 256M

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.hard

The ceiling a program cannot raise itself past.

[limits] sets what a request starts with. [limits.hard] uses the same keys and sets the most a program may ask for with Core\Config::set. A value above the ceiling returns false, and the previous value stays in force. The program keeps running.

When [limits.hard] does not set a key, the ceiling is the value the request started with. A program can then lower that limit, but it cannot raise it. There is one exception. A program you start from the command line may raise its memory limit to any value when [limits.hard] does not set memory. When [limits] does not set memory either, the start value is 128M. false removes a ceiling.

You can lower or raise a ceiling while the server runs. Edit the file and save it, and the server applies it. A request can never change a ceiling. An application may have a lower ceiling of its own than the rest of the server.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# Every request starts with 256M of memory. A program may raise its own limit up to 512M.
[limits]
memory = "256M"
[limits.hard]
memory = "512M"

The ceiling no program can raise

<?nvs
// `[limits.hard]` sets the ceilings a program cannot go past. It uses the same
// keys as `[limits]`. `[limits]` sets where a request starts, and a program may
// change those values up to the ceiling.
echo 'starts at: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
echo 'never above: ', Core\Config::get('limits.hard.memory') ?? '(unset)', "\n";
// A program may set any value up to the ceiling, and the ceiling itself.
// `512M` returns `true`. `513M` returns `false`.
echo 'ask 512M: ', Core\Config::set('limits.memory', '512M') ? 'accepted' : 'refused', "\n";
echo 'ask 513M: ', Core\Config::set('limits.memory', '513M') ? 'accepted' : 'refused', "\n";
echo 'in force: ', Core\Config::get('limits.memory'), "\n";
// A value over the ceiling does not throw an error. The previous value, `512M`,
// stays in force. `Core\Config::restore` then sets it back to `256M`.
Core\Config::restore('limits.memory');
// A program cannot change the ceiling. Each of these keys returns `false`,
// including the ones that only look like the ceiling's key.
array<string> $spellings = ['limits.hard.memory', 'limits.hard', 'app.limits.hard.memory', 'limits.hard.hard.memory'];
foreach ($spellings as string $key) {
echo 'raise ', $key, ': ', Core\Config::set($key, '4G') ? 'accepted' : 'refused', "\n";
}
// No `cpu_time` is set, so `nvs run` has no CPU time limit and no ceiling. `9h` is
// allowed. A request on a server starts with `30s`, and that is also its ceiling.
echo 'cpu ceiling: ', Core\Config::get('limits.hard.cpu_time') ?? '(not set)', "\n";
echo 'ask 9h cpu: ', Core\Config::set('limits.cpu_time', '9h') ? 'accepted' : 'refused', "\n";
Output
starts at: 256M
never above: 512M
ask 512M: accepted
ask 513M: refused
in force: 512M
raise limits.hard.memory: refused
raise limits.hard: refused
raise app.limits.hard.memory: refused
raise limits.hard.hard.memory: refused
cpu ceiling: (not set)
ask 9h cpu: accepted

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.fatal_reserve_memory

The part of a request's memory limit that is kept for the code that reports a limit error.

Every request has a memory limit, [limits] memory. A request that reaches the limit stops. The function you passed to Core\Fatal::onLimit then runs to report what happened, and it needs memory too. This setting keeps that memory free. Normal code cannot use it.

The reserve is taken from the memory limit and is not added to it. A larger reserve leaves less memory for the program. The default is 1 MiB. The reserve is never more than a quarter of the memory limit.

Only the person who runs the server sets this value. A program cannot change it, and Core\Config::set returns false.

The example prints the memory limit and the reserve, and then tries to change both. The reserve stays the same. The program may lower its own memory limit.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# Every request starts with 256M of memory. 1M of it is kept back for the error report.
[limits]
memory = "256M"
fatal_reserve_memory = "1M"

The bytes kept back for the report

<?nvs
// `limits.fatal_reserve_memory` keeps some memory back for one job. When a request
// runs out of memory, the code that reports the error runs in this memory.
// Nothing else can use it.
echo 'the heap a request starts with: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
echo 'held back for the report: ', Core\Config::get('limits.fatal_reserve_memory') ?? '(unset)', "\n";
// The reserve is part of `limits.memory`, so normal work gets the rest.
// `Core\Fatal::onLimit` registers the function that runs in the reserve.
Core\Fatal::onLimit(fn(): void => {
echo "the request stopped on a limit\n";
});
// Only the person who runs the server may set the reserve. A program cannot
// make it bigger or set it to `0`, so both calls return `false`.
string $reserve = 'limits.fatal_reserve_memory';
echo 'ask for a bigger net: ', Core\Config::set($reserve, '64M') ? 'accepted' : 'refused', "\n";
echo 'ask for no net: ', Core\Config::set($reserve, '0') ? 'accepted' : 'refused', "\n";
echo 'still: ', Core\Config::get('limits.fatal_reserve_memory') ?? '(unset)', "\n";
// A program may change `limits.memory` for itself. The reserve is then taken
// from the new value.
echo 'keep myself small: ', Core\Config::set('limits.memory', '64M') ? 'accepted' : 'refused', "\n";
echo 'heap now: ', Core\Config::get('limits.memory') ?? '(unset)', "\n";
Output
the heap a request starts with: 256M
held back for the report: 1M
ask for a bigger net: refused
ask for no net: refused
still: 1M
keep myself small: accepted
heap now: 64M

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.fatal_reserve_time

The part of a request's CPU time limit that is kept for the code that reports a limit error.

A request that uses all of its CPU time, [limits] cpu_time, stops. The function you passed to Core\Fatal::onLimit then runs to report what happened, and it needs some time to do that. This setting keeps that time free. [limits] fatal_reserve_memory does the same for memory.

The reserve is taken from the CPU time limit and is not added to it. The default is 50 milliseconds, which is enough to build a message and write it to a slow log. The reserve is never more than a quarter of the CPU time limit.

Only the person who runs the server sets this value. A program cannot change it, and Core\Config::set returns false.

The example prints the CPU time limit and both reserves, and then tries to change all three. The program may lower its own CPU time limit. Both reserves stay the same.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# When a request stops on a limit, the error report gets 1M of memory and 50 milliseconds.
[limits]
fatal_reserve_memory = "1M"
fatal_reserve_time = "50ms"

The clock kept back for the report

<?nvs
// `limits.fatal_reserve_time` keeps some time back for one job. When a request
// runs out of time, the code that reports the error runs in this time.
// `limits.fatal_reserve_memory` does the same for memory.
echo 'cpu time to start with: ', Core\Config::get('limits.cpu_time') ?? '(unset — none was written)', "\n";
echo 'clock held back: ', Core\Config::get('limits.fatal_reserve_time') ?? '(unset)', "\n";
echo 'heap held back beside it: ', Core\Config::get('limits.fatal_reserve_memory') ?? '(unset)', "\n";
// Only the person who runs the server may set either reserve. A program cannot
// make one bigger or set it to `0`, so every call returns `false`.
array<string> $net = ['limits.fatal_reserve_time', 'limits.fatal_reserve_memory'];
foreach ($net as string $half) {
echo 'widen ', $half, ': ', Core\Config::set($half, '10s') ? 'accepted' : 'refused', "\n";
echo 'drop ', $half, ': ', Core\Config::set($half, '0') ? 'accepted' : 'refused', "\n";
}
// A program may set its own `limits.cpu_time`. The time reserve is then taken
// from the new value.
echo 'bound my own cpu time: ', Core\Config::set('limits.cpu_time', '2s') ? 'accepted' : 'refused', "\n";
echo 'in force now: ', Core\Config::get('limits.cpu_time') ?? '(unset)', "\n";
Output
cpu time to start with: (unset — none was written)
clock held back: 50ms
heap held back beside it: 1M
widen limits.fatal_reserve_time: refused
drop limits.fatal_reserve_time: refused
widen limits.fatal_reserve_memory: refused
drop limits.fatal_reserve_memory: refused
bound my own cpu time: accepted
in force now: 2s

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.max_script_depth

How deep a chain of spawned scripts may nest before the next one is refused.

A script can run another in its own isolate, and that one can do the same. Nothing about such a chain says where it stops, so a program that spawns itself builds isolates until the tree runs out of heap, and the out-of-memory that arrives says nothing about the recursion behind it.

The ceiling turns that into a clear answer: a spawn past it is refused before the child exists, and the report names the depth. It holds a value when nobody writes one — sixty-four, far above anything written on purpose and well below where the heap would notice. It is the operator's to set: a script able to raise its own could exhaust the tree before any depth stopped it. Written as false, the ceiling comes off.

The example prints the ceiling this checkout runs under, and which numbers beside it a program may move.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# A script may start another script, up to 64 levels deep.
[limits]
max_script_depth = 64

How deep a chain of spawned scripts may go

<?nvs
// A script can start another script, which can start another. `limits.max_script_depth`
// is how deep this chain may go. A script past that depth does not start.
echo 'nesting allowed: ', Core\Config::get('limits.max_script_depth') ?? '(no value)', "\n";
// `limits.memory` is in the same block. A program may change it for itself.
echo 'ask for less memory: ', Core\Config::set('limits.memory', '64M') ? 'accepted' : 'not allowed', "\n";
// `Core\Config::set('limits.max_script_depth', ...)` does not compile,
// because a program may not change `limits.max_script_depth`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.
string $name = 'limits.max_script_depth';
array<string> $asks = ['1024', '8', 'false'];
foreach ($asks as string $ask) {
echo 'set the depth to ', $ask, ': ', Core\Config::set($name, $ask) ? 'accepted' : 'not allowed', "\n";
}
// The depth is still the configured value, `64`.
echo 'still in force: ', Core\Config::get('limits.max_script_depth') ?? '(unset)', "\n";
Output
nesting allowed: 64
ask for less memory: accepted
set the depth to 1024: not allowed
set the depth to 8: not allowed
set the depth to false: not allowed
still in force: 64

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.max_decompressed

The most any one decompression may produce.

A compressed archive says how large it unpacks to, and a hostile one lies: a few hundred octets on the wire can become gigabytes in a heap. This is the absolute half of the bound every Core\Compress and Core\Zip decode runs under — a ceiling on the output, applied while that output grows rather than to a buffer sized from the archive's own header, so a bomb costs the ceiling and never the size it claimed.

A call may name a smaller ceiling of its own and gets the smaller of the two; nothing raises this one, and there is no spelling for an unbounded decompression at all. Passing the bound throws rather than truncating, because a truncated decompression that looks like success is the failure the bound exists to prevent. Written nowhere, it is 64 MiB — large enough that no honest document reaches it.

The example prints the ceiling in force, works a decode against both sides of a smaller one, and asks to raise the operator's.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# One decompression may produce at most 64M.
[limits]
max_decompressed = "64M"

The most one decode may produce

<?nvs
// A small compressed input can unpack into more memory than the server has.
// `limits.max_decompressed` is the most bytes one decompression may produce.
// Every `Core\Compress` and `Core\Zip` call uses this limit.
echo 'the most one decode may produce: ', Core\Config::get('limits.max_decompressed') ?? '(unset)', "\n";
// This compresses 16 KiB of the letter `A`. The result is only 52 bytes,
// so the input is small and the output is large.
bytes $payload = Core\Str::repeat('A', 16384) as bytes;
bytes $frame = Core\Compress::compress($payload, Core\Compress::Codec::Gzip);
echo 'on the wire: ', Core\Bytes::length($frame), " octets\n";
// The third argument sets a lower limit for one call. If the output would be
// bigger, the call throws a `ParseError` and returns no partial data.
try {
Core\Compress::decompress($frame, Core\Compress::Codec::Gzip, 16383);
echo "one octet short: got the whole thing anyway\n";
} catch (ParseError $bomb) {
echo "one octet short: refused\n";
}
echo 'at its own ceiling: ', Core\Bytes::length(Core\Compress::decompress($frame, Core\Compress::Codec::Gzip, 16384)), " octets\n";
// A call that sets a higher limit still gets the configured limit. A program
// cannot change `limits.max_decompressed`, so this returns `false`.
string $name = 'limits.max_decompressed';
echo 'raise the ceiling from here: ', Core\Config::set($name, '4G') ? 'accepted' : 'refused', "\n";
echo 'still: ', Core\Config::get('limits.max_decompressed') ?? '(unset)', "\n";
Output
the most one decode may produce: 64M
on the wire: 52 octets
one octet short: refused
at its own ceiling: 16384 octets
raise the ceiling from here: refused
still: 64M

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.max_decompression_ratio

The most output a decompression may produce per octet of input.

The other half of the same bound, and the half that catches the attack. A ceiling on the output alone is one a tiny request still reaches, because being small on the wire is what a decompression bomb is for: the published ones run from ten thousand to one into a billion to one, since they are built from one repeated octet and a real document is not. So what a decode is actually measured against is the smaller of the absolute ceiling and this ratio times the octets it was handed.

A call may name a smaller ratio of its own and gets the smaller of the two; nothing raises this one, and no value switches it off. Written nowhere, it is 1000 to 1, which every corpus a text document compresses to passes comfortably.

The example prints the ratio in force, refuses a frame under a tighter one while the absolute ceiling is wide open, and asks to raise the operator's.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# One decompression may produce at most 64M, and at most 1000 bytes for each input byte.
[limits]
max_decompressed = "64M"
max_decompression_ratio = 1000

How much output one octet may buy

<?nvs
// `limits.max_decompression_ratio` is the most output bytes one decompression may
// produce for each input byte. It stops a small input from unpacking into a large one.
echo 'output per octet of input: ', Core\Config::get('limits.max_decompression_ratio') ?? '(unset)', "\n";
echo 'and the absolute ceiling: ', Core\Config::get('limits.max_decompressed') ?? '(unset)', "\n";
// 16 KiB of the letter `A` compresses to 52 bytes. The ratio is about 315,
// which is under the configured `1000`.
bytes $frame = Core\Compress::compress(Core\Str::repeat('A', 16384) as bytes, Core\Compress::Codec::Gzip);
echo 'this frame: ', Core\Bytes::length($frame), " octets in, 16384 out\n";
// The fourth argument sets a lower ratio for one call. At `2`, this input is
// over the ratio, so the call throws a `ParseError`.
try {
Core\Compress::decompress($frame, Core\Compress::Codec::Gzip, 1048576, 2);
echo "at 2 to 1: got the whole thing anyway\n";
} catch (ParseError $bomb) {
echo "at 2 to 1: not allowed\n";
}
echo 'at the deployment\'s ratio: ', Core\Bytes::length(Core\Compress::decompress($frame, Core\Compress::Codec::Gzip)), " octets\n";
// `Core\Config::set('limits.max_decompression_ratio', ...)` does not compile,
// because a program may not change `limits.max_decompression_ratio`.
// This program keeps the name in a variable. The compiler does not check a variable, so `set` runs and returns `false`.
string $name = 'limits.max_decompression_ratio';
echo 'loosen it from here: ', Core\Config::set($name, '1000000') ? 'accepted' : 'not allowed', "\n";
Output
output per octet of input: 1000
and the absolute ceiling: 64M
this frame: 52 octets in, 16384 out
at 2 to 1: not allowed
at the deployment's ratio: 16384 octets
loosen it from here: not allowed

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.memory_high_water

A warning in the log when a request comes close to its memory limit.

Every request has a memory limit, [limits] memory. This setting is a fraction between 0.0 and 1.0. When a request's highest memory use is more than that part of its limit, the server writes one Warn record to Core\Log at the end of the request. The record names the highest memory use, the limit and the route. With memory = "256M" and memory_high_water = 0.8, a request that used more than 80% of 256 MiB writes the warning.

The setting is off by default, and then nothing is logged. A value of 0 is not off: every request writes the warning. A value below 0.0 or above 1.0 is an error, and the server does not start.

Only the person who runs the server sets this value. A program cannot change it, and Core\Config::set returns false.

The example reads the setting, which is not set, and then tries to change it. Both changes fail.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# Every request starts with 256M of memory.
[limits]
memory = "256M"

Reading the warning threshold

<?nvs
// When a request uses this part of its memory limit, Novis writes a warning to the log.
// `limits.memory_high_water` sets that part.
echo 'memory limit: ', Core\Config::get('limits.memory'), "\n";
echo 'warning at: ', Core\Config::get('limits.memory_high_water') ?? '(unset)', "\n";
// Only the person who runs the server may set the warning.
// `Core\Config::set('limits.memory_high_water', ...)` does not compile,
// because a program may not change `limits.memory_high_water`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.
string $name = 'limits.memory_high_water';
echo 'warn at half: ', Core\Config::set($name, '0.5') ? 'accepted' : 'not allowed', "\n";
echo 'warn always: ', Core\Config::set($name, '0') ? 'accepted' : 'not allowed', "\n";
echo 'still: ', Core\Config::get('limits.memory_high_water') ?? '(unset)', "\n";
Output
memory limit: 256M
warning at: (unset)
warn at half: not allowed
warn always: not allowed
still: (unset)

Changelog

VersionChange
0.0.6The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change.

limits.cancel_on_disconnect

The request methods that stop as soon as their client goes away.

A client can close its connection before it gets the answer. By default the request still runs to its end, and the server throws the answer away. A request whose method is in this list stops at once instead. It runs no more code of your program, and no catch block runs.

The default is [], an empty list. A list such as ["GET", "HEAD"] suits a site where these methods only read data. The names are compared exactly, so GET and get are two different methods. Only the person who runs the server sets this list. A request cannot change it.

The example below tries to change the list from inside a request.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# A `GET` or `HEAD` request stops as soon as its client went away.
[limits]
cancel_on_disconnect = ["GET", "HEAD"]

A request cannot change the list

<?nvs
// Shows that a request cannot change `limits.cancel_on_disconnect`.
// `Core\Config::set('limits.cancel_on_disconnect', ...)` does not compile,
// because a program may not change `limits.cancel_on_disconnect`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.
// This prints `not allowed` three times.
string $name = 'limits.cancel_on_disconnect';
array<string> $lists = ['[]', '["POST"]', '["GET", "HEAD", "POST"]'];
foreach ($lists as string $list) {
echo 'set to ', $list, ': ', Core\Config::set($name, $list) ? 'accepted' : 'not allowed', "\n";
}
// `limits.memory` is in the same block, and a request may lower it. This prints `accepted`.
echo 'lower the memory: ', Core\Config::set('limits.memory', '64M') ? 'accepted' : 'not allowed', "\n";
Output
set to []: not allowed
set to ["POST"]: not allowed
set to ["GET", "HEAD", "POST"]: not allowed
lower the memory: accepted

limits.disconnect_grace

How long a request with no wall_time may run after its client went away.

A client can close its connection before it gets the answer. The request still runs to its end, and the server throws the answer away. A request with a wall_time stops at its wall_time. A request with no wall_time stops when disconnect_grace has passed since the client went away.

The default is 30s. false and 0 are not allowed, so a request always has a limit. Only the person who runs the server sets this value. A request cannot change it while it runs.

The example below reads the value and tries to change it.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# A request with no `wall_time` stops 10 seconds after its client went away.
[limits]
disconnect_grace = "10s"

Read the grace and try to change it

<?nvs
// Shows how to read `limits.disconnect_grace`. A request cannot change it.
// The `nvs.toml` beside this file sets it, so this prints `10s`.
echo 'grace: ', Core\Config::get('limits.disconnect_grace') ?? 'not set', "\n";
// `Core\Config::set('limits.disconnect_grace', ...)` does not compile,
// because a program may not change `limits.disconnect_grace`.
// This program keeps the names in variables. The compiler does not check a variable, so each `set` call runs and returns `false`.
// This prints `not allowed` three times.
string $name = 'limits.disconnect_grace';
array<string> $values = ['1h', '1s', 'false'];
foreach ($values as string $value) {
echo 'set to ', $value, ': ', Core\Config::set($name, $value) ? 'accepted' : 'not allowed', "\n";
}
Output
grace: 10s
set to 1h: not allowed
set to 1s: not allowed
set to false: not allowed