lighttpd的超时参数详解

今天服务器上传大文件,服务器php一直没有响应,响应为0KB,经排查发现是lighttpd的超时设置问题

server.max-keep-alive-idle = 5
server.max-read-idle = 60
server.read-timeout = 0
server.max-connection-idle = 360

这几个参数意思相近,配置的时候很容易搞混。

对于一个keep-alive连接上的连续请求,发送第一个请求内容的最大间隔由参数max-read-idle决定,从第二个请求起,发送请求内容的最大间隔由参数max-keep-alive-idle决定。请求间的间隔超时也由max-keep-alive-idle决定。发送请求内容的总时间超时由参数read-timeout决定。Lighttpd与后端交互数据的超时由max-connection-idle决定。

例子:

下面是模拟客户端代码:

$fp = fsockopen("127.0.0.1", 8902, $errno, $errstr, 30);

fwrite($fp, "GET / HTTP/1.1\r\n");
sleep(3);                                             //$1这个时间必须小于max-read-idle,否则会超时
fwrite($fp, "Host: a.com\r\n");
sleep(3);                                             //$2这个时间必须小于max-read-idle,否则会超时。且$1+$2时间之和必须小于read-timeout,否则超时
fwrite($fp, "Connection: Keep-Alive\r\n\r\n");
echo fread($fp, 1024);

sleep(7);                                             //$3 这个时间必须小于max-keep-alive-idle,否则超时

fwrite($fp, "GET / HTTP/1.1\r\n");
fwrite($fp, "Host: a.com\r\n");
sleep(15);                                           //$4  这个时间必须小于max-keep-alive-idle,否则超时,可以大于max-read-idle,但仍然不能超过read-timeout
fwrite($fp, "Connection: Keep-Alive\r\n\r\n");
echo fread($fp, 1024);
fclose($fp);

//以上时间均不受max-connection-idle限制

下面是模拟后端server代码:

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($sock == NULL)
{
    echo "can‘t create socket";
    exit;
}
if(!socket_bind($sock, "0.0.0.0", 8904))
{
    echo "can‘t bind socket";
    exit;
}
socket_listen($sock, 100);

while(1)
{
    if($new_conn = socket_accept($sock))
    {   
        $recv = socket_read($new_conn, 100000);
        //echo $recv;
        echo "begin sleep\n";
        sleep(10);                                                                                  //这个时间必须小于max-connection-idle,否则会超时
        echo "end sleep\n";
        socket_write($new_conn, "HTTP/1.1 200 OK\r\nDate: Tue, 01 Nov 2011 05:58:25 GMT\r\nServer: TestServer/1.0\r\nContent-Length: 1\r\nContent-Type: text/html;charset=gb2312\r\nConnection: Keep-Alive\r\n\r\na");
    }
    else
    {
        echo "accept failed!";
    }
}

下面是lighttpd中关于这几个参数实现的代码:

if (con->recv->is_closed) {                                                                        
                                                                 if (srv->cur_ts - con->read_idle_ts > con->conf.max_connection_idle) {                                              //对于客户端已经发送完请求数据的情况下,超时时间max-connection-idle
                                                                           /* time - out */
#if 1
                                                                           WARNING("(connection process timeout) [%s]", SAFE_BUF_STR(con->dst_addr_buf));
#endif
                                                                           connection_set_state(srv, con, CON_STATE_ERROR);
                                                                           changed = 1;
                                                                 }
                                                        }
                                                        else {

if (con->request_count == 1) {                   
                                                                           if (srv->cur_ts - con->read_idle_ts > con->conf.max_read_idle) {                                              //对于第一个请求,发送的数据最大时间间隔:max_read_idle
                                                                                    /* time - out */
#if 1
                                                                                    if (con->conf.log_timeouts) {
                                                                                             WARNING("(initial read timeout) [%s]", SAFE_BUF_STR(con->dst_addr_buf));
                                                                                    }
#endif
                                                                                    connection_set_state(srv, con, CON_STATE_ERROR);
                                                                                    changed = 1;
                                                                           }
                                                                 } else {                                                                                               //从第二个请求开始,发送的数据最大时间间隔:keep_alive_idle
                                                                           if (srv->cur_ts - con->read_idle_ts > con->keep_alive_idle) {
                                                                                    /* time - out */
#if 1
                                                                                    if (con->conf.log_timeouts) {
                                                                                             DEBUG("(keep-alive read timeout) [%s]", SAFE_BUF_STR(con->dst_addr_buf));
                                                                                    }
#endif
                                                                                    connection_set_state(srv, con, CON_STATE_ERROR);
                                                                                    changed = 1;
                                                                           }
                                                                 }

if (con->conf.read_timeout > 0 && con->read_start_ts > 0)                                                    //在read_timeout设置不为0的情况下,发送数据的最大总时间:read_timeout
                                                                 {
                                                                           used_time = srv->cur_ts - con->read_start_ts;
                                                                           if (used_time > con->conf.read_timeout)
                                                                           {
                                                                                    WARNING ("read timeout, client[%s], time=%lu",
                                                                                             SAFE_BUF_STR(con->dst_addr_buf), used_time);
                                                                                    connection_set_state(srv, con, CON_STATE_ERROR);
                                                                                    changed = 1;
                                                                           }
                                                                 }
                                                        }

时间: 2024-11-05 21:55:20

lighttpd的超时参数详解的相关文章

jquery ajax 方法及各参数详解

jquery ajax 方法及各参数详解 1.$.ajax() 只有一个参数:参数 key/value 对象,包含各配置及回调函数信息. 参数列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方式 ("POST" 或 "GET"), 默认为 "GET".注意:其它 HTTP 请求方法,如 PUT 和 DELETE 也可以使用,但仅部分

JQuery中$.ajax()方法参数详解

url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 delete也可以使用,但仅部分浏览器支持. timeout: 要求为Number类型的参数,设置请求超时时间(毫秒).此设置将覆盖$.ajaxSetup()方法的全局设 置. async:要求为Boolean类型的参数,默认设置为true,所有请求均为异步请求. 如果需要发送同步请求,请将此选项

SWFTOOLS PDF2SWF 参数详解

转载至:http://blog.csdn.net/iamduoluo/article/details/6820329 SWFTools提供了一系列将各种文件转成swf的工具: font2swf.exe gif2swf.exe jpeg2swf.exe pdf2swf.exe png2swf.exe wav2swf.exe 具体的功能就顾名思义了. 其中把pdf转成swf的工具就是pdf2swf了.在命令行中运行pdf2swf src.pdf des.swf一般能满足需求.而命令行参数可以通过pd

httpUrlConnection的参数详解

post方式的的请求过程: // 设置是否向httpUrlConnection输出,因为这个是post请求,参数要放在 // http正文内,因此需要设为true, 默认情况下是false; httpUrlConnection.setDoOutput(true); // 设置是否从httpUrlConnection读入,默认情况下是true; httpUrlConnection.setDoInput(true); // Post 请求不能使用缓存 httpUrlConnection.setUse

nginx配置参数详解

配置参数详解 user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍于CPU. error_log  logs/error.log;  error_log  logs/error.log  notice;  error_log  logs/error.log  info;  错误日志:存放路径. pid logs/nginx.pid; pid(进程标识符):存放路径

ASP.NET性能监视参数详解

性能监视器- Performance Monitor 性能监视器是Windows自带的系统资源和性能监视工具. 性能监视器能够量化地提供CPU使用率, 内存分配状况, 异常派发情况, 线程调度频率等信息. ASP.NET能够提供每秒钟的请求数目, 请求响应时间等等. 性能监视器能够监视一段时间内上述资源的利用情况, 提供平均值和峰值. 性能监视器有助于获取关于性能的具体指标, 监视问题出现时系统资源的变化情况. 通过检查性能监视器中一些重要计数器的变化情况, 往往能够找到一些比较有用的线索. 比

Jquery ajax 参数 详解

Jquery ajax 参数主要如下: url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 delete也可以使用,但仅部分浏览器支持. timeout: 要求为Number类型的参数,设置请求超时时间(毫秒).此设置将覆盖$.ajaxSetup()方法的全局设 置. async:要求为Boolean类型的参数,默认设置为true,所有请求均为异步

JDK中的URLConnection参数详解

JDK中的URLConnection参数详解 来自:http://www.blogjava.net/supercrsky/articles/247449.html 针对JDK中的URLConnection连接Servlet的问题,网上有虽然有所涉及,但是只是说明了某一个或几个问题,是以FAQ的方式来解决的,而且比较零散,现在对这个类的使用就本人在项目中的使用经验做如下总结: 1:> URL请求的类别: 分为二类,GET与POST请求.二者的区别在于:      a:) get请求可以获取静态页面

Nginx主配置参数详解,Nginx配置网站

1.Niginx主配置文件参数详解 a.Linux中安装nginx.博文地址为:http://www.cnblogs.com/cindy-cindy/p/6847499.html b.当Nginx安装完毕后,会有相应的安装目录,安装目录里的nginx.confg为nginx的主配置文件,nginx主配置文件分为4部分,main(全局配置).server(主机配置).upstream(负载均衡服务器设置)以及location(URL匹配特定位置的设置),这四者的关系是:server继承main,l