0

ngx.socket.tcp can't be used in log phase according to doc. https://github.com/openresty/lua-nginx-module#ngxsockettcp

but I tested and found that lua-resty-mysql, based in ngx.socket.tcp can be used in log phase, why ?

oyjh
  • 1,248
  • 1
  • 9
  • 20

1 Answers1

1

Your test wrong.

Here is small test setup

How to run:

docker-compose up

Figure out nginx port:

docker ps

Test:

curl 127.0.0.1:<port>

And here is the proof:

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"
Alexander Altshuler
  • 2,930
  • 1
  • 17
  • 27
  • I checked and found that it's used in ngx.timer instead of log phase. Thanks a lot! – oyjh Jul 04 '18 at 07:49