php安装模式mod_php和Fastcgi的选择与对比
php安装模式mod_php和Fastcgi的选择与对比
安装php又面临到了模式的选择,以前都是选择mod_php模式,因为这样安装比较方便哈,今天突然关心起FastCGI这种模式,败毒了一把,找到了一些关于mod_php和Fastcgi的选择与对比这方面的讨论,现在发出来留一个记号,以便进一步研究:
第一篇:php在apache中安装模式的区别:fastcgi和mod_php
说到fastCgi就不得不说Cgi。
CGI英文全称是 Common Gateway Interface,通常翻译为共同网关接口,是HTTP服务器与机器上的其他程序进行通信的一个接口。这个“其他程序”可以使用任何计算机语言来编写,它通过CGI这个接口从HTTP服务器取得输入,然后把运行的结果又通过CGI这个接口交给HTTP服务器,而HTTP服务器把这个结果送给浏览器。
CGI的出现让WEB从静态变为为动态,随着Web的越来越普及,很多的网站的都需要有动态的页面,以便与浏览者互交。CGI方式的缺点也越来越突出。因为HTTP要生成一个动态页面,系统就必须启动一个新的进程以运行CGI程序,不断地fork是一项很消耗时间和资源的工作。这就出现了FastCGI。
百度百科关于FastCGI
2. FastCGI 可在任何平台上使用,Netscape Enterprise 及 IIS 都有 FastCGI 的模块可供使用,阿帕契 (Apache,以及利用 Apache 衍生出做的服务器) 上也有 mod_fastcgi 可用。
3. FastCGI 支持 C/C++,Ruby, Perl,Tcl,Java,Python 等程序语言。
4. FastCGI 的应用程序亦兼容于 CGI。即 FastCGI 的应用程序也可以当成 CGI 来执行。
5. 现有的 CGI 程序要改写成 FastCGI 非常简单,最少可能只需要多加入三行程序代码。
6. FastCGI 的侦错方式与 CGI 大同小异,只要带入程序所需的环境变量及参数,即可在命令列模式执行或侦错。
7. FastCGI 应用程序的写作方式与 CGI 类似,除了几项原则要特别注意外,FastCGI 的写作方式跟 CGI 几乎一样,与学习 Web Server API 比较起来, FastCGI 简单多了。
8. FastCGI 支授分布式运算 (distributed computing),即 FastCGI 程序可以在网站服务器以外的主机上执行并且接受来自其它网站服务器来的请求。
mod_php就是把PHP做为APACHE一个内置模块。让apache http服务器本身能够支持PHP语言,不需要每一个请求就启动PHP解释器来解释PHP。
第二篇:mod_php or fastcgi性能比较与选择
用php肯定少了不这个问题的选择,cgi自然就不必说了,但是mod_php和fastcgi的争论确还是比较多的。
找了一些资料,晾在这,可供参考。
首先,性能应该是大家最关心的问题了,除了mod_php和fastcgi 的 benchmark,还有一些服务器差别的测试,如apache vs lighthttpd
1 mod_php, LightTPD, FastCGI - What’s fastest?
这个bechmark的结果是 Apache(prefork)+Fastcgi+php的性能是最好的。超过了apache+mod_php,甚至也超过了lightty+fastcgi+php。当然,这个结果得出值相差都很小。另外,以上说的几个结果都使用了APC加速,使用APC后性能提高1倍以上。
2 php4-mod-vs-cgi
这个bechmark是在php4的环境下完成的。其summary.txt的内容如下。
------------------------
PHP4 module, very simple script (phpinfo.php): requests/s
plain 130.04
+turckcache 129.42
+turckcache+zend-optimizer 125.50
PHP4 module, very complex script (insurance application): requests/s
plain 1.84
+turckcache 6.23
+turckcache+zend-optimizer 5.58
+optimizer 1.58
PHP4 CGI, very simple script (phpinfo.php): requests/s
plain 22.69
+turckcache n/a*
+turckcache+zend-optimizer n/a*
+optimizer 21.23
PHP4 CGI, very complex script (insurance application): requests/s
plain 2.00
+turckcache n/a*
+turckcache+zend-optimizer n/a*
+optimizer 1.72
* = turkcache doesn't support caching of the PHP scripts in CGI mode
上面的结果我觉得需要关注的是无cache的情况,因为使用mod_php或fastcgi主要还是用来生成动态页面。前面的cache有更好的工具来实现,如squid。所以,这个结果也是fastcgi胜出,相差也不大。
3 http://buytaert.net/drupal-performance?page=1
这个文章的结果和上面两个刚好相反。使用fastcgi代替mod_php后,”When switching from
to
we observe a 63% slowdown for anonymous visitors, and a 18% slowdown for authenticated visitors.”以下是图表
另外,benchmark中也做了和lightty的比较,如下图:
这个文章的结论是Apache+mod_php性能好于Apache+fastcgi。另外,Apache+mod_php略好于lightty+fastcgi。
4 最后看看 fastcgi官方自己怎么说的吧
Of course, the answer is that it depends upon the application. A more complete answer is that FastCGI often wins by a significant margin, and seldom loses by very much.
5 结论是,还是根据自己的应用测一下吧….
最后,个人观点
如果mod_php和fastcgi的性能相差不是很大的话,还是倾向于fastcgi的,这种方式毕竟更灵活、安全和简单。
1 使用fastcgi,你的web server 可以比较简单的切换,可以测试不同的服务器,Apache,lightty,ngix 等等,不需要有代码的修改
2 如果想换脚本的实现,如不用php,而是改成perl,python之类的,web服务器也不需要任何的改动
3 web server和fastcgi可以用不同的帐号运行,带来了一定的安全隔离
4 只在Apache中编个mod_fastcgi可以说是简单多了,把mod_php编进apache时,出问题时很难定位是php的问题还是apache的问题,我就见过这样的core,函数调用几十层,一点头绪都没有。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
