Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between nts and ts in php

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what are the differences between nts and ts in php", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what are the differences between nts and ts in php".

The difference between nts and ts in php: ts means thread safety, and multi-thread access uses a locking mechanism, so that when one thread accesses a certain data of this class, other threads cannot access it at the same time, while nts means non-thread safety and does not provide thread access protection, and multiple threads can operate on the same data at the same time.

This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.

What is the difference between nts and ts in php

In the PHP development and production environment building process, you need to install the PHP language parser. Officially provides two types of versions, thread-safe (TS) version and non-thread-safe (NTS) version, sometimes our development environment is different from the actual production environment, so we also need to choose to install the corresponding PHP version.

Take notes here for future review.

1. Introduction

TS:

TS (Thread-Safety) means thread safety, multithread access uses a locking mechanism, when one thread accesses some data of this class, the data is locked, and other threads cannot access the data at the same time, until the thread has finished reading, other threads can access and use the data. The advantage is that there will be no data inconsistency or data contamination, but it takes longer than NTS.

Select the TS version when PHP is loaded in ISAPI (commonly used by Apache).

NTS:

NTS (None-Thread Safe) is non-thread safe and does not provide data access protection. It is possible that multiple threads operate the same data successively or at the same time, which is easy to cause data confusion (that is, dirty data). The execution time of general operation is shorter than TS.

PHP loads the runtime TNS version in FAST-CGI mode, which has better performance.

ISAPI:

ISAPI (Internet Server Application Programming Interface), which is usually loaded by the http server, runs in the form of a server module and is proposed by the micro-soft, so it can only be run on the win platform, such as apache,iis under win [works more stably with fast cgi], while php on linux runs as an Apache module (commonly used) or php-fpm (which is more suitable for NGINX+PHP operation).

CGI:

Cgi (Common Gateway Interface): a tool for HTTP servers to "talk" to programs on client machines. In short, cig is a background language that can communicate with the server. At this time, php runs as a separate program, which is characterized by memory consumption.

FAST CGI:

Fast cgi is a resident (long-live) type of CGI that can be executed all the time, as long as it is activated and does not take time to fork a new process every time. This approach is a language-independent, scalable architecture CGI open extension, and its main behavior is to keep the CGI interpreter process in memory and thus achieve high performance.

FAST-CGI is an improvement scheme put forward by Microsoft to solve the deficiency of CGI interpreter. When a request sends a request to web server, web server will always fork a CGI interpreter process to process the request. After the processing is completed, the process will return the result to web server,web server and display the result. When the process ends, when the user requests the same page again, web server will fork a new process for request processing, which will be relatively inefficient (the main reason why CGI has been criticized). With the FAST-CGI interpreter, when a request is executed, the process will not be logged out, but the changed process will go into a dormant period. When a new request is received, the modified process will be re-enabled for processing. Compared with CGI, FAST-CGI reduces the resource consumption of repeated creation of processes.

Processes and threads: there are at least one or more threads in a process.

2. Select

Usually PHP + Apache is combined under win and runs in the way of ISAPI.

Under linux, it is usually divided into two categories:

Apache + PHP,PHP generally runs as a module of Apache

Nginx + PHP runs in the way of phpfast cgi, that is, php-fpm, which shows good performance for high concurrency and high load, so many websites use this way to build the environment.

Nginx is much less configured than Apache, so there is less probability of human error, but it also makes Apache more stable than Nginx.

With so much nonsense in front of me, here is the point.

Summary:

Run in ISAPI and use TS thread safe version

Run in FAST-CGI or PHP-FPM using NTS non-thread safe version

Usually under Windows, Apache + PHP selects TS, and IIS (fast-cgi) + PHP selects TNS.

Usually, Apache + PHP selects TS,Nginx + PHP and TNS under Linux

The above is about the content of this article on "what are the differences between nts and ts in php?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to judge browsers by conditional comments

    This article focuses on "how to use conditional comments to judge browsers". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use conditional comments to judge browsers!

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report