Home >Backend Development >PHP Tutorial >In-depth analysis of the difference between PHP thread-safe and non-thread-safe versions_PHP Tutorial

In-depth analysis of the difference between PHP thread-safe and non-thread-safe versions_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 14:59:21804browse

Starting from the first Windows version of PHP 3.0.17 released on October 20, 2000, all versions are thread-safe. This is because the Windows system uses a multi-process working method different from the Linux/Unix system. It adopts 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 method, 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. Therefore, 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, Microsoft has provided a 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.

There are 4 versions of Widows on PHP official http://php.net/: VC9 x86 Non Thread Safe, VC9 x86 Thread Safe, VC6 x86 Non Thread Safe, VC6 x86 Thread Safe; so what is the difference?

1. The supported servers are different
The VC9 version is for the IIS server and does not support APACHE, while the VC6 version provides support for both IIS and apache

What is VC6?
VC6 is the legacy Visual Studio 6 compiler, which is compiled using this compiler.
What is VC9?
VC9 is the Visual Studio 2008 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 choose the VC6 version;
If you are using IIS+PHP under windows, please choose the VC9 version;

2. Different running modes
PHP has 2 running modes: ISAPI and FastCGI.

The ISAPI execution method is used in the form of a DLL dynamic library, which can be executed after being requested by the user. It will not disappear immediately after processing a user request, so a thread safety check is required to improve the execution efficiency of the program. Therefore, if you are using ISAPI to execute PHP, it is recommended to choose the Thread Safe version;

The FastCGI execution method uses a single thread to perform operations, so there is no need to perform thread safety checks. Removing the protection of thread safety checks can improve execution efficiency. Therefore, if FastCGI is used to execute PHP, it is recommended to choose Non Thread Safe version.

For the apache server, the isapi method is generally selected, while for the nginx server, the FastCGI method is selected.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328149.htmlTechArticleStarting from the first Windows version of PHP 3.0.17 released on October 20, 2000, it is all thread-safe. version, this is because Windo...
is different from the multi-process working method of Linux/Unix system.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn