local handler
handler = function(premature)
if premature then
return
end
local client = require "resty.websocket.client"
local wb, err = client:new()
--接收服务端响应
while true do
local data, typ, err = wb:recv_frame()
if client.fatal then
ngx.log(ngx.ERR, 'failed to receive frame: ',err,typ)
--try to reconnect
end
if not data then
local bytes, err = wb:send_ping()
if not bytes then
ngx.log(ngx.ERR, 'failed to send ping: ', err)
end
elseif typ == 'close' then
--try to reconnet
elseif typ == 'ping' then
local bytes, err = wb:send_pong()
if not bytes then
ngx.log(ngx.ERR, 'failed to send pong: ', err)
end
elseif typ == 'pong' then
ngx.log(ngx.INFO, 'client ponged')
elseif typ == 'text' then
ngx.log(ngx.INFO,'data:[text]:',data)
-- data 处理
end
end
end
local ok, err = new_timer(2, handler)
if not ok then
log(ngx.ERR, "failed to create handler timer: ", err)
return
end
在使用nginx -s reload后,发现worker状态处于is shutting down状态,原因应该是由于死循环导致无法退出,这种情况下我该如何正常退出,或者在循环中