openresty lua-resty-mysql log阶段可以使用

openresty lua-resty-mysql can be used in log phase

根据文档,

ngx.socket.tcp 不能用于日志阶段。 https://github.com/openresty/lua-nginx-module#ngxsockettcp

但是我测试发现lua-resty-mysql, based in ngx.socket.tcp 可以在log阶段使用,为什么?

你测试错了。

这里是小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"