Starting from the first Windows version of PHP 3.0.17 released on October 20, 2000, all versions are thread-safe. This is due to the fact that Linux/Unix systems use multi-process working methods. The Windows system uses a multi-threaded working method. If you run PHP in CGI mode under IIS, it will be very slow. This is because the CGI mode is based on multi-process, not multi-thread. Generally, we will configure PHP to run in ISAPI mode. ISAPI is a multi-threaded mode, which is much faster. But there is a problem. Many commonly used PHP extensions are developed based on the multi-process thinking of Linux/Unix. When these extensions are run in ISAPI mode, they will go wrong and bring down IIS. If you use the thread-safe version, it will only cross a certain thread at most, and will not affect the security of the entire IIS.
Of course, CGI mode is the safest way to run PHP under IIS, but CGI mode requires reloading and unloading the entire PHP environment for each HTTP request, and its consumption is huge. In order to take into account the efficiency and security of PHP under IIS, someone gave the FastCGI solution. FastCGI allows PHP processes to be reused instead of reopening a process for each new request. At the same time, FastCGI can also allow several processes to execute at the same time. This not only solves the problem of excessive consumption of CGI process mode, but also takes advantage of the fact that CGI process mode does not have thread safety issues.
Therefore, if you use ISAPI to run PHP, you must use the Thread Safe (thread safe) version; and if you use FastCGI mode to run PHP, there is no need to use thread safety check, use None Thread Safe ( NTS, non-thread-safe) version can better improve efficiency.
Therefore, if you use ISAPI to run PHP, you must use the Thread Safe (thread safe) version; and if you use FastCGI mode to run PHP, there is no need to use thread safety check, use None Thread Safe (NTS, non Thread-safe) version can better improve efficiency.
Attachment: Excerpts from questions related to Moral Questions
When downloading the PHP installation file, I saw that there are two different binary files, such as Non Thread Safe and Thread Safe, as listed on this page: http://windows.php .net/download/. What does this mean and what is the difference between them?
This is mainly for web server. In Windows environment, if the web server you use is apchae or iis 7 or below, you should choose a thread-safe installation file. If you use Fast-cgi In mode, you can choose non-thread safety because web server itself can guarantee thread safety.
Of course, there is also the compiler used when compiling binary files: vc9 (vs series) vc6 (gcc)
As mentioned above, it is for web servers, and some web servers are processing application requests. When processing, multi-threading is used instead of multi-process. The threading method is prone to errors because it involves shared registers and memory. At this time, the program needs to spend some extra experience to process the data consistency in the registers, that is, to ensure the consistency of the data in the registers. Thread safe.
So whether to use thread safety mainly depends on the PHP request processing method used by your web server. If it is multi-threaded processing, then please choose thread safety, otherwise choose non-thread safety, as mentioned above Fast-cgi The method can choose non-thread-safe