Home>Article>Backend Development> What is the difference between Thread Safe and None Thread Safe in php

What is the difference between Thread Safe and None Thread Safe in php

青灯夜游
青灯夜游 Original
2021-06-03 14:48:29 2221browse

Difference: Thread Safe means thread safety, and a thread (thread) safety check will be performed during execution to prevent starting new threads when there are new requirements and exhausting system resources; while None Thread Safe means non-thread safety. No thread safety checks are performed during execution.

What is the difference between Thread Safe and None Thread Safe in php

The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer

The Windows version of PHP starts from version 5.2.1 There are Thread Safe (thread safe) and None Thread Safe (non-thread safe). What is the difference between the two?

  • None Thread Safe means non-thread safety, and no thread (thread) safety check is performed during execution.

  • Thread Safe means thread safety. Thread safety checks will be performed during execution to prevent new threads from being started when there are new requirements and exhausting system resources.

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 multiple The difference in how processes work is that 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 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, errors will occur 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 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.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the difference between Thread Safe and None Thread Safe in php. For more information, please follow other related articles on the PHP Chinese website!

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