Hello! 2014-05-08 3:34 GMT-07:00 Evil Mybliss: > 我在nginx里做一个统计实时流量的应用. 大概就是记录每5分钟的请求流量. 这一段代码是写在log_by_lua环境下. > 我打算使用ngx.timer.at做一个定时器, 过5分钟就post一次数据到某个url上. 我看到ngx.timer.at文档里写不能使用 > ngx.location.capture这个方法. > 请问还有其他办法实现吗? ngx.timer.at 回调的上下文并不允许使用子请求,但很多其他 API是可以使用的,包括非阻塞的 cosocket API: https://github.com/openresty/lua-nginx-module#ngxsockettcp 你可以直接使用 cosocket API 访问远方服务,或者使用第三方现成的某个 lua-resty-http 库,例如 https://github.com/pintsized/lua-resty-http#readme 比如我的 lua-resty-upstream-healthcheck 库就使用了这种方式: https://github.com/openresty/lua-resty-upstream-healthcheck#readme 另外,lua-resty-logger-socket 库的实现策略也很值得参考: https://github.com/cloudflare/lua-resty-logger-socket#readme Regards, -agentzh