PHP thread-safe and non-thread-safe version of the difference in-depth analysis

Source: Internet
Author: User
Tags vc9 nginx server

The Windows version of PHP from version 5.2.1 started with the thread safe (thread safe) and None thread safe (NTS, non-thread-safe) of the points, the difference is where? Which one should I use? Here to do a simple introduction

The first Windows version of PHP3.0.17, released on October 20, 2000, started with a thread-safe version, because unlike the Linux/unix system, which works in a multi-process manner, Windows systems work in a multi-threaded way. It is very slow to run PHP as CGI under IIS, because the CGI pattern is built on a multi-process basis, not multithreaded.

In general, we will configure PHP to run in ISAPI way, ISAPI is multi-threaded way, so much faster. There is a problem, however, that many commonly used PHP extensions are developed with Linux/unix's multi-process thinking, which can be faulted when running in ISAPI mode. Therefore, the CGI mode under IIS is the safest way to run PHP, but the CGI mode requires reloading and uninstalling the entire PHP environment for each HTTP request, which consumes a huge amount.

To take into account the efficiency and security of PHP under IIS, Microsoft has given the fastcgi solution. FastCGI can allow the PHP process to be reused instead of every new request to re-open a process. FastCGI can also allow several processes to execute simultaneously. This solves the problem that the CGI process pattern consumes too much, and the CGI process pattern does not have the advantage of the thread security problem.

Therefore, if you are using ISAPI to run PHP, you must use the thread safe version, while running PHP in fastcgi mode, there is no need to use thread security, with none thread safe (NTS, non-thread-safe) Version to better improve efficiency.

PHP official http://php.net/on the Widows version has 4: VC9 x86 Non thread SAFE,VC9 x86 thread SAFE,VC6 x86 Non thread SAFE,VC6 x86 thread SAF e; So what's the difference?

1. Supported servers are different
The VC9 version is for the IIS server version, there is no support for Apache, and the VC6 version provides support for both IIS and Apache

What is VC6?
VC6 is Legacy Visual Studio 6 compiler, which is compiled with this compiler.
What is VC9?
VC9 is the Visual Studio compiler, which is compiled with Microsoft's VS editor.

So how do we choose which version of PHP to download?
If you are using apache+php under Windows, please select the VC6 version;
If you are using iis+php under Windows, please select the VC9 version;

2. Different modes of operation
PHP has 2 running modes: ISAPI and fastcgi.

ISAPI execution mode is used in the form of DLL dynamic library, can be executed after the user request, after processing a user request will not disappear immediately, so the need for thread security check, so as to improve the execution efficiency of the program, so if it is to execute PHP with ISAPI, it is recommended to choose thread Safe version;

The fastcgi execution is performed with a single thread, so there is no need for thread security checks, and the removal of thread safety checks can improve execution efficiency, so if PHP is executed in fastcgi, it is recommended to choose the non thread safe version.

For Apache servers, the ISAPI mode is generally chosen, and for Nginx server, the fastcgi mode is chosen.

PHP thread-safe and non-thread-safe version of the difference in-depth analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.