简体   繁体   English

mod_php和cgi php脚本有什么区别?

[英]What are the differences between mod_php and cgi php script?

What are the differences between mod_php and cgi php script? mod_php和cgi php脚本有什么区别?

I mean, why it's better (is it?) to use mod_php instead simple php scripts, running them as CGIs? 我的意思是,为什么更好(是吗?)使用mod_php而不是简单的PHP脚本,将它们作为CGI运行?

Thanks 谢谢

When using CGI : a PHP process is launched by Apache, and it is that PHP process that interprets PHP code -- not Apache itself . 使用CGI时:Apache启动了一个PHP进程,正是PHP进程解释了PHP代码 - 而不是Apache 本身

In theory, a distinct PHP process has to be created for each request -- which makes things slower : Apache has more work to do to answer a request. 理论上,必须为每个请求创建一个独特的PHP进程 - 这会使事情变得更慢:Apache有更多工作要做以回答请求。
(Well, as pointed out by @AlReece45 in a comment, this can be made better using FastCGI) (好吧,正如@ AlReece45在评论中指出的那样,使用FastCGI可以做得更好)


When using PHP as an Apache module ( mod_php , or mod_php5 ) , the PHP interpreter is kind of " embedded " inside the Apache process : there is no external PHP process. 当使用PHP作为Apache模块mod_phpmod_php5 )时 ,PHP解释器在Apache进程中是一种“ 嵌入式 ”:没有外部PHP进程。

Which means : 意思是 :

  • No forking to answer a request (faster) 没有分叉回答请求(更快)
  • Better communication between Apache and PHP Apache和PHP之间更好的沟通


Generally speaking, I would say that mod_php is the solution that's used the most. 一般来说,我会说mod_php是最常用的解决方案。

Plain CGI requires process to be spawned for each request at the time of request. 普通CGI要求在请求时为每个请求生成进程。

mod_php requires you to use bloated apache instead of slick nginx or lighttpd. mod_php要求你使用膨胀的apache而不是光滑的nginx或lighttpd。 Besides, "better communication between Apache and PHP" mentioned by Pascal may harm apache (it harms anyone who develops in php!;-)). 此外,Pascal提到的“Apache和PHP之间更好的通信”可能会损害apache(它会危害任何在php开发的人!;-))。

FastCGI lets you separate php from the web server (possibly run it on the different host). FastCGI允许您将php与Web服务器分开(可能在不同的主机上运行它)。

Also, php.net just released a vulnerability today where source code disclosure is possible if you are using mod_cgi to run PHP and your PHP version is older than PHP 5.3.12 or PHP 5.4.2 . 此外,php.net刚刚发布了一个漏洞,如果您使用mod_cgi运行PHP并且您的PHP版本早于PHP 5.3.12PHP 5.4.2,则可能会泄露源代码。

http://www.php.net/archive/2012.php#id2012-05-03-1 http://www.php.net/archive/2012.php#id2012-05-03-1

Patch by upgrading or applying a mod_rewrite rule. 通过升级或应用mod_rewrite规则修补程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM