我正在使用这个tutorial在我的新 Web 服务器上安装 nginx、php 和 mysql。
本教程使用 ISPConfig 3,并且可以选择是使用 FastCgi 还是 PHP-FPM。
我想知道两者哪个更好。就性能和速度而言,两者中哪一个与 nginx 内联使用最好?
顺便说一句,我还在我的服务器上启用了 memcached 和 xcache。
最佳答案
PHP-FPM 比 PHP 的旧 FastCGI 处理要好得多。从 PHP 5.3.3 开始,PHP-FPM 已成为核心,旧的 FastCGI 实现不再可用。
我的答案只是被否决了(在上线相当长一段时间之后),我明白为什么,所以这里列出了为什么 PHP-FPM 实际上比旧的 FastCGI 实现更好。
首先,PHP 社区中的 FastCGI 实现很糟糕这一点早已众所周知。可以在 https://wiki.php.net/ideas/fastcgiwork 找到的文档页面它说:
php-cgi is not useful in production environment without additional “crutches” (e.g. spawn-fcgi from lighttpd distribution or php-fpm patch). This project assumes integration of such “crutches” and extending php-cgi to support for different protocols.
- daemonization (detach, pid file creation, setup environment variables, setuid/setgid/chroot)
- graceful restart
- separate and improve transport layer to allow support for different protocols
- support for SCGI protocol
- support for subset of HTTP protocol
- …
以下是 PHP-FPM 做得更好的事情的列表,摘自 http://php-fpm.org/about/ :
- PHP daemonization: pid file, log file,
setsid()
,setuid()
,setgid()
,chroot()
- Process Management. Ability to “gracefully” stop and start PHP workers without losing any queries. This allows gradually updating the configuration and binary without losing any queries.
- Restricting IP addresses from which requests can come from.
- Dynamic number of processes, depending on the load (adaptive process spawning).
- Starting the workers with different uid/gid/chroot/environment and different
php.ini
options (no need for safe mode).- Logging
STDOUT
andSTDERR
.- Ability to emergency restart all the processes in the event of an accidental destruction of the shared memory opcode cache, if using an accelerator.
- Forcing the completion of process if
set_time_limit()
fails.Additional features: - Error header - Accelerated upload support -
fastcgi_finish_request()
- Slowlog with backtrace
关于nginx - 使用 Nginx Web 服务器的 FastCgi 与 PHP-FPM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17141596/