Use limit_rate_after and limit_rate together to control the data transfer rate for individual CDN requests. Both functions apply per-request — they do not control global bandwidth.
limit_rate_after
Sets the maximum amount of data transfer before throttling begins.
| Item | Details |
|---|---|
| Syntax | limit_rate_after(n, unit) |
| Return value | true on success, false on failure |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
n | integer | Yes | Maximum data transfer before throttling begins. If unit is omitted, n is in bytes. |
unit | char | No | Unit for n. Valid values: K, M, G (case-insensitive). |
limit_rate
Sets the rate to which data transfer is throttled after the limit_rate_after threshold is reached.
The minimum enforced rate is 50 KB/s. If you specify a lower value, the rate is throttled to 50 KB/s.
| Item | Details |
|---|---|
| Syntax | limit_rate(n, unit) |
| Return value | true on success, false on failure |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
n | integer | Yes | Throttled data transfer rate. If unit is omitted, n is in bytes per second. |
unit | char | No | Unit for n. Valid values: K, M, G (case-insensitive). |
Example
Use limit_rate_after and limit_rate together to let a request transfer data at full speed up to a threshold, then cap the rate:
limit_rate_after(100, 'k')
limit_rate(1, 'm')
// The first 100 KB transfers at full speed. After that, the rate is capped at 1 MB/s.