Home  >  Article  >  Backend Development  >  What does nts mean in php

What does nts mean in php

青灯夜游
青灯夜游Original
2021-09-02 18:59:346793browse

In PHP, nts refers to "non-thread safety", which means that it does not provide data access protection and does not perform thread (thread) security checks during execution; in this way, multiple threads may change data one after another. Then the result is dirty data.

What does nts mean in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

nts full name is one-Thread Safe, that is, non-thread Security means that data access protection is not provided, and thread security checks are not performed during execution; it is possible that multiple threads may change data successively, resulting in dirty data.

Since there is non-thread safety, there is also thread safety (Thread Safe).

Thread Safe means thread safety. Thread safety checks will be performed during execution to prevent the CGI execution method of starting new threads when there are new requirements from exhausting system resources.

The difference between PHP thread safety and non-thread safety:

Because: Linux/Unix system uses a multi-process working method, while Windows system uses multi-threading Way of working.

That is: the basic unit of task scheduling in the Linux system is the process, and the basic unit of task scheduling in the Windows system is the thread;

Generally we will configure PHP to run in the way of ISAPI, ISAPI is The multi-threaded approach 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 provides 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;

But if you use FastCGI mode to run PHP, there is no It is necessary to use thread safety check. Using None Thread Safe (NTS, non-thread safe) version can better improve efficiency.

How should I choose which one to use (PHP thread-safe, PHP non-thread-safe)?

windos server:

1. If you are PHP IIS; please choose: PHP non-thread safe (None Thread Safe (NTS));

2. If you are PHP apache; please choose: PHP Thread Safe (TS)

linux server:

PHP under the linux server, there is no PHP thread-safe or non-thread-safe version Distinguishing;

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does nts mean 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