1. Why shouldn't I use Apache 2 in a production environment?
The following answer is based in this modified excerpt of a mail by Rasmus Lerdorf.
Apache 2 is a complete rewrite and a complete architecture change from Apache 1. It is not like going from PHP 3 to PHP 4 or from PHP 4 to PHP 5. There is a lot of code that is common, and certainly the base architecture of PHP has not changed for years. So comparing Apache 1 vs. Apache 2 to PHP 4 vs. PHP 5 makes no sense. The architecture has been proven over the years and the code, while somewhat unwieldy in places, is a known entity. PHP from the very early days was designed against this basic Apache 1 architecture and works extremely well running under it.
The major feature that draws people to Apache 2 is threading. On Windows where most basic libraries are, and must be, threadsafe, Apache 2 does actually make sense and it would be good to work out the kinks on that platform. However, on UNIX there are a lot of basic libraries where thread safety is an unknown. And this is not about PHP extensions, it is about 3rd-party libraries underneath PHP's hundreds of extensions. Whether any one 3rd-party library is threadsafe is really hard to determine. There are a lot of variables involved, including which OS, which version of the OS, which libc, which version of that libc and on some platforms even the compiler flags used to compile these things. And to make it even more fun, tracking down a thread safety problem is damn well near impossible. Hundreds of people may well state that Apache+PHP+ext/foo works perfectly for them, but maybe they are only getting about a million hits a day. Then another user comes along who gets 100 million hits a day and uses a fast dual-cpu machine and everything blows up because now suddenly the window for some tiny race condition has been made much larger due to the faster cpu speeds, the second cpu and the higher frequency of requests. And the bug report we get from this user will be something along the lines of:
It don't work sometimes. Most of the times it works fine, but then every now and then it just don't. The error is different each time and I have no idea how to reproduce it, but fix it right away!!!
What can we do about these?
There are a number of (fixable) technical reasons Rasmus does not think Apache2+PHP is a good idea in a production environment, but setting those aside it really boils down to one simple concept:
PHP is glue. It is the glue used to build cool web applications by sticking dozens of 3rd-party libraries together and making it all appear as one coherent entity through an intuitive and easy to learn language interface. The flexibility and power of PHP relies on the stability and robustness of the underlying platform. It needs a working OS, a working web server and working 3rd-party libraries to glue together. When any of these stop working PHP needs ways to identify the problems and fix them quickly. By making the underlying framework more complex by not having completely separate execution threads, completely separate memory segments and a strong sandbox for each request to play in, a feet of clay is introduced into PHP's system.
Using the prefork mpm with Apache 2 to avoid the threading is possible, and yes using a standalone fastcgi mechanism to avoid the threading, too, but then defining characteristic of the web server of choice are avoided. At this point in its development, Rasmus still maintains that one is better off simply sticking with Apache 1 for serving up PHP pages with the one caveat that Apache 1 sucks pretty badly on Windows. |