The Challenge - PHP on Windows
PHP was originally written for a multi-process environment (Apache) and
is therefore most commonly used with the popular LAMP (Linux, Apache,
MySQL, PHP) platform. Under Windows, things work differently. Literally
all of the Web Servers under Windows, including IIS and Apache, are
multi-threaded, which means that a single process handles all
concurrent clients. For PHP to run properly under a multithreaded
server, it must be designed with Thread Safety in mind. Failure to do
so will cause instability and may often result in unexpected crashes.
To make things worse, a crash in a multithreaded environment will
typically cause the entire Web Server to go down, as opposed to
multi-process environment, where a typical crash will only affect one
request and can generally go unnoticed.
Up until today, the only way to prevent PHP crashes on Windows was to
run PHP as an external process to the Web Server via CGI.
for "Common Gateway Interface". CGI is a communication platform for a
Web Server to speak with Web Server applications such as PHP. CGI was
created as the standard interface for Web Server applications. Its main
benefits are simplicity, language independence and most importantly -
process isolation. This isolation prevents known bugs in PHP from
crashing the Web Server. CGI also has some significant drawbacks -
mainly performance. The CGI mechanism involves huge overhead resulting
in poor performance caused by the initialization of a new PHP process
for each request, and then its shuts down when the request is done.
Native Web Server Modules:
In response to the performance problems of CGI, several vendors have
developed APIs for their servers. Well-known APIs are NSAPI from
Netscape and ISAPI from Microsoft. The APIs enable PHP to run in the
server process, which is persistent across all requests, saving
initialization overhead. APIs are naturally used when PHP is run on a
single process server, but that’s not the case for multi-threading
servers. While parts of PHP were rewritten to make it thread-safe, the
thread-safe version never matured to be as stable and as efficient as
the multi-process version. In a nutshell, the smallest bug in PHP, one
of its modules, or one of the 3rd party libraries that it uses, that
causes one thread to become corrupted, can infiltrate all server
threads and bring the entire server down. For that reason, implementing
PHP on Windows using a native server plug-in (whether IIS or Apache)
proved to be impractical, resulting in frequent, yet random crashes.