echo_sleep

The `echo_sleep` directive pauses the processing of requests for a specified duration.

Syntaxecho_sleep time;
Defaultnone
Contextlocation, if in location
Arguments1

Description

The echo_sleep directive is part of the NGINX echo module and allows users to introduce a deliberate pause in the request processing. This can be particularly useful when simulating delays in responses for testing purposes or to handle asynchronous behavior gracefully. The directive accepts one argument: the sleep duration, specified in seconds. It can also accept fractional seconds for finer granularity.

When using echo_sleep, the directive blocks the request for the defined duration before it continues processing the remainder of the NGINX configuration for that request. This has implications on performance, especially in high-throughput situations. Therefore, it should be used judiciously and primarily in testing environments, rather than in production configurations, where it might lead to performance degradation or increased latency for user requests.

Given its placement in the configuration, echo_sleep can be used in both location blocks and if conditions within those locations. As such, understanding its placement context is crucial for achieving the intended behavior without unintended side effects or conflicts with other directives.

Config Example

location /sleep_example {
    echo_sleep 2;  # pauses for 2 seconds
    echo 'Response after sleep.';
}

Overusing this directive can lead to significant performance bottlenecks.

Using fractional seconds may not behave as expected if not supported by the server configuration.

← Back to all directives