Discussion on the difference between TS and NTS of php

  • 2021-11-29 23:19:59
  • OfStack

ts(Thread-Safety) That is, thread safety. When accessing by multiple threads, locking mechanism is adopted. When one thread accesses a certain data of this class, it is protected, and other threads cannot access it until the thread finishes reading it, and other threads can use it. This version is selected when php is loaded in ISAPI mode. This version is selected when php is loaded in ISAPI mode.

nts(None-Thread Safe) That is, it is non-thread-safe, that is, it does not provide data access protection. It is possible that multiple threads change data one after another, resulting in dirty data. When php runs in fast cgi, this version is selected, which has better performance;

ISAPI (Internet Server Application Programming Interface), which is usually loaded by http server and runs as a server module, is proposed by Microsoft, so it can only run on win platform, such as apache and iis under win [it is said that fast cgi works more stably], while php on linux runs as Apache module or php-fpm.

cgi (Common Gateway Interface): The HTTP server "talks" with programs on your or other machines. To put it bluntly, cig is a background language that can communicate with the server. At this time, php runs as a separate program. It is characterized by consuming memory.

fast cgi. Is a resident (long-live) CGI, which can be executed directly, and does not take time to go to fork every time after activation. This is a language-independent, scalable CGI open extension, and its main behavior is to keep CGI interpreter process in memory and thus achieve high performance.

ISAPI execution mode is used in the form of DLL dynamic library, which can be executed after being requested by users, and will not disappear immediately after processing one user request, so thread safety check is needed to improve the execution efficiency of the program. Therefore, if ISAPI is used to execute PHP, it is recommended to select ThreadSafe version.
However, FastCGI executes with a single thread, so there is no need for thread safety check, and the execution efficiency can be improved by removing the protection of thread safety check. Therefore, if FastCGI executes PHP, it is recommended to select NonThread Safe version.
Through phpinfo (); Look at the Thread Safety item. This item is to see if it is thread safe. If it is: enabled, 1 should be ts version in general, otherwise it is nts version.

The above is the difference between TS and NTS of php. If you have any questions, please leave me a message and this site will reply to you in time. Thank you very much for your support to this site!


Related articles: