我的nginx.conf如下
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
lua_shared_dict dict 10m;
server {
listen 80;
server_name localhost;
access_log logs/access.log;
error_log logs/error.log;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /abc {
lua_code_cache off;
content_by_lua '
ngx.say(ngx.now())
ngx.sleep(10)
ngx.say("success")
ngx.say(ngx.now())
ngx.exit(200)
';
}
location /test {
default_type 'text/plain';
lua_code_cache off;
content_by_lua '
ngx.log(ngx.ERR, "onerequest")
local res = ngx.location.capture("/abc?id=" .. tostring(id))
ngx.print(res.body)
ngx.exit(200)
';
}
}
}
刚才又测试了,不管是macos 还是linux,用curl是没有问题的。但是用浏览器的话,确实用ngx.say输入时间是10秒,但是浏览器就不行。
浏览器里输入:http://localhost/test?id=5 过了10秒后输出:
1387939200.985
success
1387939210.994
同时再开一个tab,输入http://192.168.0.3/test?id=50,过了很久输出:
1387939203.359
success
1387939213.363
同时再开一个tab,输入http://localhost/test?id=5,过了很久输出:
1387939211.026
success
1387939221.035
输出的时间确实是10s,curl也是正确的,但是浏览器就不正确。虽然浏览器输出的时间是正确的,但是浏览器过了约20秒的时间才显示结果。用的浏览器是chrome版本 30.0.1599.101 m 和firefox25.0.1,都有这样的问题。
这是firefox的截图:
第二个请示在第一个请求之后1-2秒内就结束(目测)了,但是第三个请求又过了10秒(目测)才结束。
------------------ 原始邮件 ------------------
发件人: "lhmwzy";<lh...@gmail.com>;
发送时间: 2013年12月25日(星期三) 上午8:02
收件人: "openresty"<openresty@googlegroups.com>;
主题: Re: [openresty] ngx.sleep ngx.location.capture有bug吗?
我这里也未重现此问题
openresty 1.4.3.9
FreeBSD 8.2(X86)
在 2013年12月25日 上午1:56,Yichun Zhang (agentzh) <age...@gmail.com> 写道:
> Hello!
>
> 2013/12/24 李恒:
>>
>> 访问:http://localhost/test?id=5
>> 同时发起两个请求,第一个请求需要等待10秒有结果,第一个请求需要等待20秒才有结果
>> 这是什么原因?
>>
>
> 你使用的是什么版本的 ngx_lua (或者 ngx_openresty)?你使用的是什么操作系统?
>
> 在我的 Linux x86_64 系统上,使用 ngx_openresty 1.4.3.9(带有 ngx_lua
> 0.9.3)运行你的例子,并不能复现需要等待 20 秒才出结果的请求:
>
> $ time curl 'http://localhost/test?id=5'
>
> real 0m10.024s
> user 0m0.002s
> sys 0m0.005s
>
> $ time curl 'http://localhost/test?id=5'
>
> real 0m10.015s
> user 0m0.005s
> sys 0m0.003s
>
> $ time curl 'http://localhost/test?id=5'
>
> real 0m10.023s
> user 0m0.003s
> sys 0m0.004s
>
> Regards,
> -agentzh
>
> --
> --
> 邮件来自列表“openresty”,专用于技术讨论!
> 订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
> 发言: 请发邮件到 openresty@googlegroups.com
> 退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
> 归档: http://groups.google.com/group/openresty
> 官网: http://openresty.org/
> 仓库: https://github.com/agentzh/ngx_openresty
> 教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 openresty@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html