开发者

What are the differences between mod_php and cgi php script?

What are the开发者_StackOverflow differences between mod_php and cgi php script?

I mean, why it's better (is it?) to use mod_php instead simple php scripts, running them as CGIs?

Thanks


When using CGI : a PHP process is launched by Apache, and it is that PHP process that interprets PHP code -- not Apache itself.

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.
(Well, as pointed out by @AlReece45 in a comment, this can be made better using 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.

Which means :

  • No forking to answer a request (faster)
  • Better communication between Apache and PHP


Generally speaking, I would say that mod_php is the solution that's used the most.


Plain CGI requires process to be spawned for each request at the time of request.

mod_php requires you to use bloated apache instead of slick nginx or lighttpd. Besides, "better communication between Apache and PHP" mentioned by Pascal may harm apache (it harms anyone who develops in php!;-)).

FastCGI lets you separate php from the web server (possibly run it on the different host).


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.

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

Patch by upgrading or applying a mod_rewrite rule.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜