Home >Backend Development >PHP Tutorial >A brief discussion on the difference between thread safety and non-thread safety in PHP
This article mainly talks about the difference between TS and NTS in PHP. Interested friends can learn about it.
ts (Thread-Safety) means thread safety. When accessed by multiple threads, a locking mechanism is adopted. When a thread accesses certain data of this class, it is protected and other threads cannot access it until this thread After reading, other threads can use it. There will be no data inconsistency or data pollution. Select this version when php is loaded in ISAPI mode. Select this version when php is loaded in ISAPI mode.
nts (None-Thread Safe) is not thread-safe, that is, it does not provide data access protection. It is possible that multiple threads change the data one after another, resulting in dirty data. Select this when PHP is running in fast cgi mode. This version has better performance;
ISAPI (Internet Server Application Programming Interface), usually refers to being loaded by the http server and running in the form of a server module. It was proposed by Microsoft, so it can only be used on the win platform Run on, for example, apache and iis under win [it is said that fast cgi works more stably], while php on linux runs in the form of Apache module or php-fpm.
cgi (Common Gateway Interface): A tool for the HTTP server to "talk" with your program or other machines. To put it bluntly, cgi is a background language that can communicate with the server. communication. At this time, php is running as an independent program. The characteristic is that it consumes memory.
fast cgi. It is a long-live CGI. It can be executed all the time. As long as it is activated, it will not take time to fork every time. This method is independent of language. A CGI open extension with a scalable architecture whose main behavior is to keep the CGI interpreter process in memory and thus obtain higher performance.
[Recommended course: PHP video tutorial]
The above is the detailed content of A brief discussion on the difference between thread safety and non-thread safety in PHP. For more information, please follow other related articles on the PHP Chinese website!