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

发布于 2024-08-30 21:54:36 字数 108 浏览 1 评论 0原文

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

我的意思是,为什么最好(是吗?)使用 mod_php 而不是简单的 php 脚本,并将它们作为 CGI 运行?

谢谢

What are the 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尤怨 2024-09-06 21:54:36

使用 CGI 时:PHP 进程由 Apache 启动,并且由该 PHP 进程解释 PHP 代码,而不是 Apache 本身。

理论上,必须为每个请求创建一个不同的 PHP 进程——这会使速度变慢:Apache 需要做更多的工作来响应请求。

(嗯,正如 @AlReece45 在评论中指出的,使用 FastCGI 可以做得更好)

当使用 PHP 作为 Apache 模块mod_phpmod_php5 时,PHP 解释器是一种“嵌入式” “ Apache 进程内部:没有外部 PHP 进程。

这意味着:

  • 无需分叉来回答请求(更快)
  • Apache 和 PHP 之间更好的通信

一般来说,我认为 mod_php 是最常用的解决方案。

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.

狼性发作 2024-09-06 21:54:36

普通 CGI 要求在请求时为每个请求生成进程。

mod_php 要求你使用臃肿的 apache 而不是光滑的 nginx 或 lighttpd。此外,Pascal 提到的“Apache 和 PHP 之间更好的通信”可能会损害 apache(它会损害任何使用 php 开发的人!;-))。

FastCGI 允许您将 php 与 Web 服务器分开(可能在不同的主机上运行它)。

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).

短暂陪伴 2024-09-06 21:54:36

此外,php.net 今天刚刚发布了一个漏洞,如果您使用 mod_cgi 运行 PHP 并且您的 PHP 版本早于 PHP 5.3.12PHP 5.4.2

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

通过升级或应用 mod_rewrite 规则进行修补。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文