search
HomeBackend DevelopmentPHP Tutorialmod_fastcgi和mod_fcgid的区别_PHP

FastCGI

mod_fcgid是一个跟mod_fastcgi二进制兼容的Apache module。

原来的mod_fastcgi因为实现方式的限制,所以可能会创建了很多不必要的进程,而实际上只需要更少的进程就能处理同样的请求。 mod_fastcgi的另外一个问题是每一个CGI的多个进程都共享同一个管道文件,所有到同一个fastcgi的通讯都通过这个同名的管道文件进行, 这样当出现通讯错误的时候,根本不知道正在通讯的是哪一个fastcgi,于是也没有办法将这个有问题的进程杀死。

mod_fcgid尝试使用共享内存来解决这个问题。共享内存里面有当前每个fastcgi进程的信息(包括进程号,进程使用的管道文件名等),当 每次尝试请求fastcgi工作的时候,Apache将会首先在共享内存里面查询,只有在共享内存里面发现确实没有足够的fastcgi进程了,才会创建 新的进程,这样可以保证当前创建的进程数量刚好能够处理客户的请求。另外,由于每一个fastcgi进程使用不同名称的管道文件,所以可以在通讯失败的时 候知道到底哪个fastcgi进程有问题,而能够尽早的将其剔除。

程序实现的目标

跟mod_fastcgi二进制兼容
只要在Apache中用mod_fcgid替换了mod_fastcgi,就能工作。原来的fastcgi程序不用重新编译,立即可以工作。


更严格的控制进程的创建
Apache中每一个request handler都能通过共享内存知道当前系统fastcgi运行的情况,这样可以防止过度的创建fastcgi进程,无谓的消耗系统的资源。


简单清晰的进程创建速度控制策略

每一个fastcgi都会维护一个计数器,这个计数器在程序创建和程序结束的时候都会增加,而这个计数器每秒会减1,直到0。当计数器的值高于某个 阀值的时候,程序就会停止创建,直到计数器的值回落。这样既可以保证在请求突然增多的时候能够快速反应(特别是Apache刚启动,需要大量创建程序的时 候),也能保证当fastcgi程序有问题,不断重起的时候,重起的速度不会过高而消耗过多的系统资源。


自动检测出有问题的进程

因为每个fastcgi使用自己特定的管道文件,所以在通讯错误的时候可以轻易知道哪一个程序出现问题,而尽早的将其剔除。


可移植性
遵照Apache2的习惯,所有可移植的代码都放到一起,所有不可移植的代码都在arch目录下分开存放。当前已经测试过的系统包括 Linux , FreeBSD(已经包含入FreeBSD4和FreeBSD5的port中), Solaris, Windows 2000.


支持FastCGI方式运行的PHP

可以直接支持以FastCGI方式运行的PHP。因为PHP现在还不能保证所有的扩展代码都是线程安全的,所以并不建议在Apache2的线程模式 下使用mod_php。而以FastCGI方式运行的PHP则是其中一个解决办法。另外,使用mod_fcgi还可以在不修改任何PHP代码的情况下,获 得数据库连接池的功能,大大减少PHP进程到数据库的连接。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP vs. Python: Understanding the DifferencesPHP vs. Python: Understanding the DifferencesApr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP: Is It Dying or Simply Adapting?PHP: Is It Dying or Simply Adapting?Apr 11, 2025 am 12:13 AM

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The Future of PHP: Adaptations and InnovationsThe Future of PHP: Adaptations and InnovationsApr 11, 2025 am 12:01 AM

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

When would you use a trait versus an abstract class or interface in PHP?When would you use a trait versus an abstract class or interface in PHP?Apr 10, 2025 am 09:39 AM

In PHP, trait is suitable for situations where method reuse is required but not suitable for inheritance. 1) Trait allows multiplexing methods in classes to avoid multiple inheritance complexity. 2) When using trait, you need to pay attention to method conflicts, which can be resolved through the alternative and as keywords. 3) Overuse of trait should be avoided and its single responsibility should be maintained to optimize performance and improve code maintainability.

What is a Dependency Injection Container (DIC) and why use one in PHP?What is a Dependency Injection Container (DIC) and why use one in PHP?Apr 10, 2025 am 09:38 AM

Dependency Injection Container (DIC) is a tool that manages and provides object dependencies for use in PHP projects. The main benefits of DIC include: 1. Decoupling, making components independent, and the code is easy to maintain and test; 2. Flexibility, easy to replace or modify dependencies; 3. Testability, convenient for injecting mock objects for unit testing.

Explain the SPL SplFixedArray and its performance characteristics compared to regular PHP arrays.Explain the SPL SplFixedArray and its performance characteristics compared to regular PHP arrays.Apr 10, 2025 am 09:37 AM

SplFixedArray is a fixed-size array in PHP, suitable for scenarios where high performance and low memory usage are required. 1) It needs to specify the size when creating to avoid the overhead caused by dynamic adjustment. 2) Based on C language array, directly operates memory and fast access speed. 3) Suitable for large-scale data processing and memory-sensitive environments, but it needs to be used with caution because its size is fixed.

How does PHP handle file uploads securely?How does PHP handle file uploads securely?Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

What is the Null Coalescing Operator (??) and Null Coalescing Assignment Operator (??=)?What is the Null Coalescing Operator (??) and Null Coalescing Assignment Operator (??=)?Apr 10, 2025 am 09:33 AM

In JavaScript, you can use NullCoalescingOperator(??) and NullCoalescingAssignmentOperator(??=). 1.??Returns the first non-null or non-undefined operand. 2.??= Assign the variable to the value of the right operand, but only if the variable is null or undefined. These operators simplify code logic, improve readability and performance.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),