Hi ,
I now implemented it in the following way .
location /try {
content_by_lua '
function multi ()
local sock = ngx.socket.tcp()
sock:settimeout(1000)
local ok, err = sock:connect("172.16.4.42", 8080)
if not ok then
ngx.log(ngx.CRIT,"connect failed")
ngx.status = 503
ngx.say("service unavailable")
ngx.exit(503)
ngx.exit(ngx.NGX_ERROR);
end
local reqline = string.format("GET / HTTP/1.1\\r\\nHOST:localhost\\r\\n\\r\\n")
sock:settimeout(1000)
local bytes, err = sock:send(reqline)
sock:settimeout(1000)
local line, err, partial = sock:receiveuntil("\\r\\n")
if not line then
ngx.log(ngx.CRIT,"receive failed")
ngx.status = 503
ngx.say("service unavailable")
ngx.exit(503)
ngx.exit(ngx.NGX_ERROR);
end
local ret , err = sock:setkeepalive(0,900000)
end
local t1 = ngx.thread.spawn(multi)
local t2 = ngx.thread.spawn(multi)
local t3 = ngx.thread.spawn(multi)
local t4 = ngx.thread.spawn(multi)
local t5 = ngx.thread.spawn(multi)
local t6 = ngx.thread.spawn(multi)
local t7 = ngx.thread.spawn(multi)
local t8 = ngx.thread.spawn(multi)
local t9 = ngx.thread.spawn(multi)
local t10 = ngx.thread.spawn(multi)
ngx.thread.wait(t1, t2, t3 , t4 , t5 , t6 , t7 , t8 , t9 , t10 )
I am having issues with the following code
local line, err, partial = sock:receiveuntil("\\r\\n")
if not line then
ngx.log(ngx.CRIT,"receive failed")
Is this the right way ?
thank you for your time.
On Thursday, August 21, 2014 5:46:27 AM UTC+5:30, agentzh wrote:
Hello!
On Wed, Aug 20, 2014 at 10:38 AM, pete wilde wrote:
> res1, res2, = ngx.location.capture_multi{
> { "/foo" },
> { "/bar" },
> }
> process the res1 and res2 .
>
Use of ngx.thread API and cosockets API (or some lua-resty-http
libraries based on that) for this can usually be more efficient than
ngx.location.capture_multi().
Regards,
-agentzh