rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 应用技术 » Web服务器

lighttpd通过fastcgi结合php

lighttpd提供了一个接口,外部程式支持的FastCGI接口,FastCGI是一个独立于平台,和服务器,应用程序独立的一个接口

fastcgi简介:

1:fastcgi消除了很多cgi的局限性,cgi在每个请求完成后会自动重新启动,导致性能不佳
2:fastcig保持进程一直运行并等待请求,消除了fork过程,减少了整体启动和消亡的时间.
3:cgi程序通过管道和服务器进行通讯,fastcgi通过unix套接字或者TCP/IP和服务器进行通讯,也就是说fastcgi选项不仅可以运行于网络服务器本身,而且包括所有的网络
4:fastcgi内部提供了一个负载均衡器,对比apache+mod_php,fastcgi提供的额外安全性,可以运行于不同的权限服务器.

fastcgi模块配置选项:

( "host" => <string> ,
      "port" => <integer> ,
      "socket" => <string>,                 # either socket or host+port
      "bin-path" => <string>,               # optional
      "bin-environment" => <array>,         # optional
      "bin-copy-environment" => <array>,    # optional
      "mode" => <string>,                   # optional
      "docroot" => <string> ,               # optional if "mode" is not "authorizer"
      "check-local" => <string>,            # optional
      "min-procs" => <integer>,             # optional
      "max-procs" => <integer>,             # optional
      "max-load-per-proc" => <integer>,     # optional used for adaptive spawning of fcgi processes for versions below 1.3.14
      "idle-timeout" => <integer>,          # optional
      "broken-scriptfilename" => <boolean>, # optional
      "disable-time" => <integer>,          # optional
      "allow-x-send-file" => <boolean>,     # optional
      "kill-signal" => <integer>,           # optional (v1.4.14+ though option is accepted in earlier versions)
    ),

host/port:fastcgi进程的host和端口
bin-path:本地fastcgi二进制文件
socket:unix套接字文件
mode:responder和authorizer模式
docroot:出于安全原因,因此建议把这个docroot以外server.document根树
disable-time:等待fasgcgi后端去检查的时间
allow-x-send-file:controls if X-LIGHTTPD-send-file and X-Sendfile headers are allowed
max-procs:设置开始最大的进程数量
max-load-per-proc:在一个新的进程产生之前,平均每个进程可以等待的处理数量
idle-timeout:在一个不可活动进程消亡前可以存活的时间
bin-environment:进程标识符

Load-Balancing:负载均衡
The FastCGI plugin provides automaticly a load-balancing between multiple FastCGI servers

Adaptive Process Spawning

假如你想至少有一个fastcgi进程去处理更多的请求,可以设置min-procs and max-procs.

FastCGI and Programming Languages:

PHP provides 2 special environment variables which control the number of spawned workers under the control of a single watching process (PHP_FCGI_CHILDREN)

and the number of requests what a single worker handles before it kills itself.

fastcgi.server = ( ".php" =>
( "localhost" =>     # "host"=>"127.0.0.1",
    #"port"=>4000,
    "socket" => "/data/lighttpd/php-fastcgi.socket",
    "bin-path" => "/data/lighttpd/fcgi/php",
    "check-local"=>"disable",
    "min-procs"=>3,
    "max-procs"=>10,
    "max-load-per-proc" => 4,
    "idle-timeout" => 20,
    "bin-environment" => (
    "PHP_FCGI_CHILDREN" => "16",
    "PHP_FCGI_MAX_REQUESTS" => "10000" ),
    "bin-copy-environment" => (
    "PATH", "SHELL", "USER" ) )
)

num-procs = max-procs * ( 1 + PHP_FCGI_CHILDREN )

10 * (16 + 1) = 170 procs

顶一下
(0)
踩一下
(0)