Installing the PHP Engine as a CGI Program
The CGI interface affords a great deal of versatility in how you install and manage the PHP engine. Unfortunately, CGI imposes performance and state penalties. Table 1 presents some pros and cons of the PHP engine as a CGI.
Table 1: Why Use CGI?
|
Pros |
Cons |
|---|---|
|
Unique PHP engines. You can compile the PHP engine with unique options for each directory or for each virtual server. |
Large performance penalty. CGI is expensive because a new process must be executed for each request. This can require expensive CPU and memory resources to launch, process, and terminate a request. For languages that are parsed (for example, PHP, Perl, Shell), where a virtual machine has to be created and the script itself parsed and compiled before the final execution, this is a resource-expensive and time-expensive operation. |
|
Platform portability. The nature of CGI provides a great deal of portability from server to server, as well as from operating system to operating system. |
Inability of PHP engine to directly communicate with HTTP engine. PHP functions (such as |
Installing the PHP Engine as a FastCGI Server
The FastCGI interface provides much of the scalability of native APIs with much of the versatility of the CGI interface by keeping the executed binary running from request to request instead of terminating after a single request. Table 2 presents some pros and cons of the PHP engine as FastCGI.
Table 2: Why Use FastCGI?
|
Pros |
Cons |
|---|---|
|
Unique PHP engines. You can compile the PHP engine with unique options for each directory or for each virtual server. |
Some performance penalty. FastCGI achieves performance improvements by not terminating a process after servicing a request. Regardless, the process runs outside the server memory, and a performance penalty is inevitable due to the out-of-process communication required between Web Server and the PHP engine. |
|
Platform portability. The nature of FastCGI provides a great deal of portability from server to server and from operating system to operating system, requiring only that Web Server understand how to interact with the FastCGI server processes. |
Inability of PHP engine to directly communicate with HTTP engine. PHP functions (such as |
Installing the PHP Engine as an NSAPI Plugin
The NSAPI interface is the native API for Web Server and provides a highly scalable environment in which third-party applications can run. The PHP engine is run as part of the server process, has direct access to the memory where requests are stored, and can manipulate them as is appropriate. Table 3 presents some pros and cons of the PHP engine as NSAPI.
Table 3: Why Use NSAPI?
|
Pros |
Cons |
|---|---|
|
Highly scalable. Multithreaded, multiprocess environment is massively scalable (see Notes on Web Server Architecture). |
Thread safety. NSAPI applications need to be thread safe. Application code that is not thread safe can crash Web Server. |