@@ -1471,8 +1471,8 @@ This hook is often used to create per-worker reoccurring timers (via the [ngx.ti
1471
1471
end
1472
1472
end
1473
1473
1474
- local ok , err = new_timer(delay, check)
1475
- if not ok then
1474
+ local hdl , err = new_timer(delay, check)
1475
+ if not hdl then
1476
1476
log(ERR, "failed to create timer: ", err)
1477
1477
return
1478
1478
end
@@ -3217,6 +3217,7 @@ Nginx API for Lua
3217
3217
* [ ngx.thread.kill] ( #ngxthreadkill )
3218
3218
* [ ngx.on_abort] ( #ngxon_abort )
3219
3219
* [ ngx.timer.at] ( #ngxtimerat )
3220
+ * [ ngx.timer.every] ( #ngxtimerevery )
3220
3221
* [ ngx.timer.running_count] ( #ngxtimerrunning_count )
3221
3222
* [ ngx.timer.pending_count] ( #ngxtimerpending_count )
3222
3223
* [ ngx.config.subsystem] ( #ngxconfigsubsystem )
@@ -7568,7 +7569,7 @@ See also [lua_check_client_abort](#lua_check_client_abort).
7568
7569
7569
7570
ngx.timer.at
7570
7571
------------
7571
- ** syntax:** * ok , err = ngx.timer.at(delay, callback, user_arg1, user_arg2, ...)*
7572
+ ** syntax:** * hdl , err = ngx.timer.at(delay, callback, user_arg1, user_arg2, ...)*
7572
7573
7573
7574
** context:** * init_worker_by_lua* ; , set_by_lua* ; , rewrite_by_lua* ; , access_by_lua* ; , content_by_lua* ; , header_filter_by_lua* ; , body_filter_by_lua* ; , log_by_lua* ; , ngx.timer.* ; , balancer_by_lua* ; , ssl_certificate_by_lua* ; , ssl_session_fetch_by_lua* ; , ssl_session_store_by_lua* ; *
7574
7575
@@ -7594,7 +7595,7 @@ Premature timer expiration happens when the Nginx worker process is
7594
7595
trying to shut down, as in an Nginx configuration reload triggered by
7595
7596
the ` HUP ` signal or in an Nginx server shutdown. When the Nginx worker
7596
7597
is trying to shut down, one can no longer call ` ngx.timer.at ` to
7597
- create new timers with nonzero delays and in that case ` ngx.timer.at ` will return ` nil ` and
7598
+ create new timers with nonzero delays and in that case ` ngx.timer.at ` will return a "conditional false" value and
7598
7599
a string describing the error, that is, "process exiting".
7599
7600
7600
7601
Starting from the ` v0.9.3 ` release, it is allowed to create zero-delay timers even when the Nginx worker process starts shutting down.
@@ -7653,6 +7654,9 @@ One can also create infinite re-occurring timers, for instance, a timer getting
7653
7654
end
7654
7655
```
7655
7656
7657
+ It is recommended, however, to use the [ ngx.timer.every] ( #ngxtimerevery ) API function
7658
+ instead for creating recurring timers since it is more robust.
7659
+
7656
7660
Because timer callbacks run in the background and their running time
7657
7661
will not add to any client request's response time, they can easily
7658
7662
accumulate in the server and exhaust system resources due to either
@@ -7692,6 +7696,25 @@ This API was first introduced in the `v0.8.0` release.
7692
7696
7693
7697
[ Back to TOC] ( #nginx-api-for-lua )
7694
7698
7699
+ ngx.timer.every
7700
+ ---------------
7701
+ ** syntax:** * hdl, err = ngx.timer.every(delay, callback, user_arg1, user_arg2, ...)*
7702
+
7703
+ ** context:** * init_worker_by_lua* ; , set_by_lua* ; , rewrite_by_lua* ; , access_by_lua* ; , content_by_lua* ; , header_filter_by_lua* ; , body_filter_by_lua* ; , log_by_lua* ; , ngx.timer.* ; , balancer_by_lua* ; , ssl_certificate_by_lua* ; , ssl_session_fetch_by_lua* ; , ssl_session_store_by_lua* ; *
7704
+
7705
+ Similar to the [ ngx.timer.at] ( #ngxtimerat ) API function, but
7706
+
7707
+ 1 . ` delay ` * cannot* be zero,
7708
+ 1 . timer will be created every ` delay ` seconds until the current Nginx worker process starts exiting.
7709
+
7710
+ When success, returns a "conditional true" value (but not a ` true ` ). Otherwise, returns a "conditional false" value and a string describing the error.
7711
+
7712
+ This API also respect the [ lua_max_pending_timers] ( #lua_max_pending_timers ) and [ lua_max_running_timers] ( #lua_max_running_timers ) .
7713
+
7714
+ This API was first introduced in the ` v0.10.9 ` release.
7715
+
7716
+ [ Back to TOC] ( #nginx-api-for-lua )
7717
+
7695
7718
ngx.timer.running_count
7696
7719
-----------------------
7697
7720
** syntax:** * count = ngx.timer.running_count()*
0 commit comments