Answer the question
In order to leave comments, you need to log in
The wait() function does not work in Lua on nginx - what to do?
Hello, I decided to write a script that would give back not immediately, but after a while. In other words, I wanted to make a LongPoll mechanism.
Here is the code:
local key = ngx.md5(ngx.var.remote_addr)
local time = ngx.req.start_time
local json = require('json')
local memcached = require('resty.memcached')
local cache = memcached:new()
local ok, error = cache:connect('127.0.0.1', 11211)
local method = ngx.var.request_method
if (method == 'GET') then
local args = ngx.req.get_uri_args()
local wait = tonumber(args['wait']) or 1
for i = 1, wait do
wait(1000)
end
end
ngx.say(wait)
[error] 18984#18984: *45 lua entry thread aborted: runtime error: /var/www/html/init.lua:15: attempt to call local 'wait' (a number value)
stack traceback:
coroutine 0:
/var/www/html/init.lua: in function /www/html/init.lua:1>, client: 46.61.242.35, server: _, request: "GET /lua_init HTTP/1.1", host: "185.159.129.71"
Answer the question
In order to leave comments, you need to log in
Name your local variable wait something else, it looks like it overrides the global one
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question