What are the technical differences between the Thread Safe and Non Thread safe PHP Windows Installation Packages?
I'm currently about to install PHP for an Apache/Windows-based development environment, but it seems I'm about to fall at the first hurdle: Choosing the right package to install.
PHP is available in no less than four flavours:
- VC9 x86 Non Thread Safe
- VC9 x86 Thread Safe
- VC6 x86 Non Thread Safe
- VC6 x86 Thre开发者_开发问答ad Safe
What's the difference between these versions in a practical sense?
If this wasn't complicated enough, version 5.3 of PHP is only available in VC9 (with 5.2 coming with the VC6 packages). And yet, according to the PHP site, you should not use VC9 with Apache... So why does Apache get the older version?
It's all very confusing and I'd like some help understanding the choices.
After a lot of research, I've managed to find my own answers to this question.
In its most basic form, the answer is: What version of PHP you should install comes down what webserver you are running.
Here's a deeper explanation of the terms used in picking a version of PHP based on what I learned:
VC6 vs VC9
Firstly, different versions of Apache for Windows are compiled with different compilers. For example, the versions on Apache.org are designed to be compiled using Microsoft Visual C++ 6, also known as VC6. This compiler is very popular, but also very old. (It dates back to 1998.)
There are different versions of Apache made for different compilers. For example, the versions available for download from ApacheLounge.com are designed to be compiled with the popular and more much recent compiler, Microsoft Visual C++ 9 from 2008. Also known as VC9.
(Note: These two compilers are the two most popular options. So while it's possible to have a VC7, VC8, etc. compiled version of Apache, it's unlikely that you'll come across them.)
The use of this more recent compiler (VC9) is important because the latest versions of PHP are only being distributed in VC9 form (although older versions are still available for VC6).
On top of that, according to ApacheLounge there are numerous improvements when using a version of Apache compiled with VC9, "in areas like Performance, MemoryManagement and Stability".
If that wasn't enough, the developers of PHP made the following statement on their site:
Windows users: please mind that we do no longer provide builds created with Visual Studio C++ 6 (VC6). It is impossible to maintain a high quality and safe build of PHP for Windows using this unmaintained compiler.
We recommend the VC9 Apache builds as provided by ApacheLounge.
All PHP users should note that the PHP 5.2 series is NOT supported anymore. All users are strongly encouraged to upgrade to PHP 5.3.6.
In all, this is an extremely compelling argument to use VC9 versions of Apache and PHP, if you ask me.
So if you're using a version of Apache from the official Apache site, it will be compiled with VC6, and as such, you should use the older version of PHP for that compiler. If you're using a version of Apache compiled with VC9, like the one available on ApacheLounge.com, you can use the latest version of PHP (for VC9).
For me, running a local development environment, it would be preferable to have the latest version of PHP, so a VC9 version of Apache is required, so I can use the VC9 version of PHP.
Thread Safe vs Non Thread Safe
Once again this comes down to your webserver. By default Apache is installed on Windows as Module, but it can be changed to run as FastCGI. There's plenty of differences between the two, but essentially FastCGI is more modern, faster, more robust, and more resource hungry. For someone running a local development environment, FastCGI might be overkill, but apparently lots of hosting companies run as FastCGI for the reasons I've stated, so there are good arguments for doing so in a development environment.
If you're running Apache (or IIS) as FastCGI (or CGI) then you want the Non Thread Safe version of PHP. If you're running Apache as default (as a Module), then you'll want the more traditional Thread Safe version.
Please note: This all only applies to Windows users.
I'm not going to bother with FastCGI (unless someone convinces me otherwise), so for me, I want the VC9 Thread Safe version of PHP.
And that's it.
Further reading:
- Official statement regarding PHP and VC6
- Difference between PHP thread safe and non thread safe binaries
- FastCGI at Wikipedia
- FastCGI for IIS
- Visual C++ at Wikipedia
- Compile your own PHP (explanation of VC6/VC9)
Personally, I use a virtualised LAMP server. Every hosting service I use is on some flavour of Linux, and there are too many differences between WAMP and LAMP. Then I just use the default tasksel LAMP server for that version of Linux.
My actual setup right now is with VMWare (Fusion on Mac, Player on Windows). I have 3 VMs - one for PHP5.3 with Ubuntu 10.04 LTS, and another for PHP 5.1 on Ubuntu 8.04 LTS. (One of the hosts I use is on RedHat, which currently supports only PHP 5.1). I have a third VM for RubyOnRails dev.
In other words, I try to get my development environment as close to my production environment as possible. So work out what version of Apache and PHP is on your host, and use that as your guide.
精彩评论