openresty lua-resty-mysql 可以在日志阶段中使用

根据文档,ngx.socket.tcp 不能在日志阶段中使用。 https://github.com/openresty/lua-nginx-module#ngxsockettcp

但是我测试了一下发现,基于 ngx.socket.tcp 的 lua-resty-mysql 在日志阶段中可以使用,为什么?

点赞
用户2060502
用户2060502

你的测试有误。

这里是一个小的test setup

运行方式:

docker-compose up

找到 nginx 端口:

docker ps

测试:

curl 127.0.0.1:<port>

以下为证明:

nginx_1 | 2018/07/02 09:03:05 [error] 7#7: *1 failed to run log_by_lua*: /usr/local/openresty/lualib/resty/mysql.lua:520: API disabled in the context of log_by_lua*
nginx_1 | stack traceback:
nginx_1 |  [C]: in function 'tcp'
nginx_1 |  /usr/local/openresty/lualib/resty/mysql.lua:520: in function 'new'
nginx_1 |  log_by_lua(nginx.conf:61):3: in function <log_by_lua(nginx.conf:61):1> while logging request, client: 192.168.112.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1:33195"
2018-07-02 09:17:12