php和apache如何通信,apache与php的通信过程

apache与php的通信方式有3中:

cgi模式      cgi、fast-cgi

非cgi模式  module

cgi模式中:

cgi模式每次请求到达apache、apache启动cgi 发送代码 解释器计算 返回数据给apache 也就是fork-execute模式

这种模式速度慢(php解释器不是常驻内存的)、占用空间(请求一次开启一次cgi)。已经被fast-cgi代替

fast-cgi 模式 :

fast-cgi 是常驻内存 与apache是两个独立的进程 ,通过端口进行通信。

*unix 下有 php-fpm

windows下有php-cgi    默认处理500次后自动退出 需要进程守护程序自动打开新的php-cgi(win上面是相当蛋疼的)

nginx就是以这种方式与php通信的

运行速度快,apache与php独立运行 php挂掉不会影响apache的运行

但是在交互过程中会出现偏差

module模式:load module php5apache2_2.dll

php作为apache的一个模块运行,随apache一起启动,属于一个进程,之间的通信是内部通信。

nginx与php通信需要与 php的cgi通信

win下面是php-cgi *unix下面有php-fpm或者其他的

启动php cgi进程:

php-cgi -d 端口号

nginx配置:

location ~ \.php$ {# php结尾的文件进行下面配置指定的方式处理

root html;

fastcgi_pass 127.0.0.1:php-cgi端口;# fastcgi的地址以及端口 便于通信

fastcgi_index index.php; # 默认文件

#指定php中$_SERVER数组中SCRIPT_FILENAME的值

#请求到nginx后 nginx将文件通过php解释器处理 这时候相当于nginx与php的通信

#传递的参数就不同

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

这时候需要对php.ini进行一些修改

fastcgi.impersonate = 1;

开启这个选项就ok,选项具体的意思:

fastcgi.impersonate string

FastCGI under IIS supports the ability to impersonate security tokens of the calling client.

IIS下的fastcgi支持 模仿 客户端安全令牌的能力

This allows IIS to define the security context that the request runs under.

允许定义 IIS所发送请求的安全性上下文环境

mod_fastcgi under Apache does not currently support this feature (03/17/2002) Set to 1 if running under IIS.

Default is zero.

也就是在cgi模式要开启这个选项

相关的其他参数解释:

fastcgi.impersonate string 默认关闭

FastCGI under IIS supports the ability to impersonate security tokens of the calling client.

IIS下的fastcgi支持 模仿 客户端安全令牌的能力

This allows IIS to define the security context that the request runs under.

允许定义 IIS所发送请求的安全性上下文环境

mod_fastcgi under Apache does not currently support this feature (03/17/2002) Set to 1 if running under IIS.

Default is zero.

cgi模式下模拟数据与web服务器通信

----------------------------------------------------------

cgi.force_redirect boolean 默认开启

cgi.force_redirect is necessary to provide security running PHP as a CGI under most web servers.

有必要在web服务器下提供安全的将php作为CGI运行

Left undefined, PHP turns this on by default. You can turn it off at your own risk.

-----------------------------------------------------------

cgi.fix_pathinfo boolean 默认开启

Provides real PATH_INFO/ PATH_TRANSLATED support for CGI.

PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the CGI specs.

php的处理是将SCRIPT_FILENAME设置为PATH_TRANSLATED 且不去分析path_info的值

Setting this to 1 will cause PHP CGI to fix its paths to conform to the spec.

A setting of zero causes PHP to behave as before. It is turned on by default.

You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED.

开启这个使CGI模式对PATH_INFO类型的url的支持

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值