Lua Nginx | Openresty: Flushes the system write buffers


We use method ngx.flush :

location = /test/flush {	
		default_type 'text/html';
		content_by_lua_block{ 
			for i = 1, 10 do
				ngx.print("<br> Line "..i..".")
				ngx.flush(true)
				ngx.sleep(2)
			end
			ngx.say("Done.")
		}
	}

Demo: http://5.161.72.222/test/flush

Line 1.
Line 2.
Line 3.
Line 4.
Line 5.
Line 6.
Line 7.
Line 8.
Line 9.
Line 10.Done.

Leave a Reply