First thing first, which one is the fastest of serving PHP source?
Here's a nice comparison on various PHP implementations in Apache:
http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html
Interesting points here:
Apache's mod_php
Apache's mod_php is the most widely used mode for PHP with Apache. mod_php itself is the entire PHP interpreter embedded in each Apache process that gets spawned. This provides performance and stability benefits, e.g.
No need to call an external process (e.g. CGI).
No need to communicate with another process via sockets (e.g. Fast CGI).
The APC cache is shared by all Apache processes.
It also has some disadvantages
The memory footprint per Apache process is large, specially when sites indulge in contributed modules.
If Apache is serving static content, e.g. images and CSS files, it still has to spawn large processes because of the embedded PHP interpreter.
CGI
CGI (Common Gateway Interface) is the legacy way of runing applications on the web from the mid 1990s or so. It was too inefficient for anything but small sites. CGI spawns a new process for every incoming request to execute a PHP script, a very resource intensive and inefficient way of doing things. No wonder it faded away over time as web applications became more complex.
FastCGI
FastCGI was introduced to avoid some of the issues with running languages, including PHP, inside the Apache process, as well as avoiding the inefficiency of CGI.
A FastCGI application is executed outside of the web server (Apache or other wise), and waits for requests from the web server using a socket. The web server and the FastCGI application can even be on separate physical machines and communicate over the network.
Because the web server and the application processes are separate better isolation is possible.
In reality, running PHP as mod_fastcgi with Apache has proved to be problematic. Mainly with stability. Even on Drupal.org we tried it for a while, but switched back to mod_php after some time.
mod_fcgid
mod_fcgid was introduced to be binary compatible with FastCGI, but with better control over spawning processes. The benefits of process isolation are still there.
Looks like a brief history on how CGI evolves.
mod_fcgid is a high performance alternative to mod_cgi or mod_cgid, which starts a sufficient number instances of the CGI program to handle concurrent requests, and these programs remain running to handle further incoming requests.
The Apache Software Foundation and the Apache HTTP Server Project are pleased to announce the release of version 2.3.9 of mod_fcgid, a FastCGI implementation for Apache HTTP Server versions 2.0, 2.2, and 2.4. This version of mod_fcgid is a security release.
I have been searching around for the way to implement mod_fcgid in Apache 2.4 for Windows which is embedded in XAMPP 1.8.x package.
Here's the procedure that would work on Windows:
1. Please download the zip package via the following link:
https://www.apachelounge.com/download/win32/modules-2.4/mod_fcgid-2.3.9-win32.zip
2. Stop Apache service.
3. Expand and extract the library file “mod_fcgid.so” and then copy it under the directory C:\xampp\apache\modules\.
4. Create new configuration file with the following content (adjust the actual paths of XAMPP installation directory to suit the needs):
C:\xampp\apache\conf\extra\httpd-fcgid.conf
##################################################################
# Configuration for mod_fcgid
# FileName: conf/extras/mod_fcgid_php.conf
# Fast CGI module Settings (PHP 5.3, 5.4)
FcgidInitialEnv PHPRC "C:\\xampp\\php"
FcgidInitialEnv PATH "C:\\xampp\\php;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;"
FcgidInitialEnv SystemRoot "C:\\Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP"
FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP"
FcgidInitialEnv windir "C:\\WINDOWS"
# Fast CGI module Settings (PHP 5.2)
# FcgidInitialEnv PHPRC "C:/php/"
# FcgidInitialEnv PATH "C:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
# FcgidInitialEnv SystemRoot "C:/Windows"
# FcgidInitialEnv SystemDrive "C:"
# FcgidInitialEnv TEMP "C:/WINDOWS/TEMP"
# FcgidInitialEnv TMP "C:/WINDOWS/TEMP"
# FcgidInitialEnv windir "C:/WINDOWS"
# Global mod_fcgid settings
FcgidIOTimeout 40
FcgidConnectTimeout 10
FcgidMaxProcesses 8
FcgidOutputBufferSize 64
ProcessLifeTime 240
FcgidMaxRequestsPerProcess 500
FcgidMinProcessesPerClass 0
# Global Config Example
# Comment out next 4 lines to use per-Directory or per-VirtualHost configuration
#Options ExecCGI
Options Indexes FollowSymLinks ExecCGI
AddHandler fcgid-script .php
FcgidWrapper "C:/xampp/php/php-cgi.exe" .php
#
# Examples below show how you can use per-Directory and per- VirtualHost Configs
# You can use multiple Directory and VirtualHost Configs at the same time
#
# Per Directory Config Example
#
#
# FcgidInitialEnv PHPRC "C:/php"
# AddHandler fcgid-script .php
# Options Indexes FollowSymLinks ExecCGI
# AllowOverride all
# FcgidWrapper "C:/php/php-cgi.exe" .php
# Require all granted
#
# Per VirtualHost Config Example
#
#
# DocumentRoot /Apache22/htdocs/fcgi
# ServerName fcgi.local
# ErrorLog logs/fcgi.error.log
# CustomLog logs/fcgi.access.log common
# FcgidInitialEnv PHPRC "C:/php"
#
# AddHandler fcgid-script .php
# Options Indexes FollowSymLinks ExecCGI
# AllowOverride all
# FcgidWrapper "C:/php/php-cgi.exe" .php
# Require all granted
#
#
# Do not comment out below line
######################################################################
5. Add new lines to the following configuration file:
C:\xampp\apache\conf\httpd.conf
…
#LoadModule watchdog_module modules/mod_watchdog.so
#LoadModule xml2enc_module modules/mod_xml2enc.so
LoadModule fcgid_module modules/mod_fcgid.so
…
#FCGI Module
Include "conf/extra/httpd-fcgid.conf"
#End of file
6. Comment out several lines to the following configuration file:
C:\xampp\apache\conf\extra\httpd-xampp.conf
…
#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php5ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadModule php5_module "C:/xampp/php/php5apache2_4.dll"
#Comment out to use purely mod_fcgid to serve all .php files, see httpd-fcgid.conf
#
# SetHandler application/x-httpd-php
#
#
# SetHandler application/x-httpd-php-source
#
…
7. Start Apache service and test the web pages.
8. Examine and check if the libraries (including mod_fcgid) are loading properly via http://localhost/xampp/phpinfo.php