Home Backend Development PHP Tutorial PHP的线程安全与非线程安全版本的区别_PHP

PHP的线程安全与非线程安全版本的区别_PHP

Jun 01, 2016 pm 12:13 PM
fastcgi Thread safety

  Windows版的PHP从版本5.2.1开始有Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分,这两者不同在于何处?到底应该用哪种?这里做一个简单的介绍。

  从2000年10月20日发布的第一个Windows版的PHP3.0.17开始的都是线程安全的版本,这是由于与Linux/Unix系统是采用多进程的工作方式不同的是Windows系统是采用多线程的工作方式。如果在IIS下以CGI方式运行PHP会非常慢,这是由于CGI模式是建立在多进程的基础之上的,而非多线程。一般我们会把PHP配置成以ISAPI的方式来运行,ISAPI是多线程的方式,这样就快多了。但存在一个问题,很多常用的PHP扩展是以Linux/Unix的多进程思想来开发的,这些扩展在ISAPI的方式运行时就会出错搞垮IIS。因此在IIS下CGI模式才是 PHP运行的最安全方式,但CGI模式对于每个HTTP请求都需要重新加载和卸载整个PHP环境,其消耗是巨大的。

  为了兼顾IIS下PHP的效率和安全,微软给出了FastCGI的解决方案。FastCGI可以让PHP的进程重复利用而不是每一个新的请求就重开一个进程。同时FastCGI也可以允许几个进程同时执行。这样既解决了CGI进程模式消耗太大的问题,又利用上了CGI进程模式不存在线程安全问题的优势。

  因此,如果是使用ISAPI的方式来运行PHP就必须用Thread Safe(线程安全)的版本;而用FastCGI模式运行PHP的话就没有必要用线程安全检查了,用None Thread Safe(NTS,非线程安全)的版本能够更好的提高效率。

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The relationship between C++ function parameter passing methods and thread safety The relationship between C++ function parameter passing methods and thread safety Apr 12, 2024 pm 12:09 PM

Function parameter passing methods and thread safety: Value passing: Create a copy of the parameter without affecting the original value, which is usually thread safe. Pass by reference: Passing the address, allowing modification of the original value, usually not thread-safe. Pointer passing: Passing a pointer to an address is similar to passing by reference and is usually not thread-safe. In multi-threaded programs, reference and pointer passing should be used with caution, and measures should be taken to prevent data races.

How to implement a thread-safe cache object in Python How to implement a thread-safe cache object in Python Oct 19, 2023 am 10:09 AM

How to implement a thread-safe cache object in Python As multi-threaded programming becomes more and more widely used in Python, thread safety becomes more and more important. In a concurrent environment, when multiple threads read and write shared resources at the same time, data inconsistency or unexpected results may result. In order to solve this problem, we can use thread-safe cache objects to ensure data consistency. This article will introduce how to implement a thread-safe cache object and provide specific code examples. Using Python’s standard library thre

Concurrency control and thread safety in Java collection framework Concurrency control and thread safety in Java collection framework Apr 12, 2024 pm 06:21 PM

The Java collection framework manages concurrency through thread-safe collections and concurrency control mechanisms. Thread-safe collections (such as CopyOnWriteArrayList) guarantee data consistency, while non-thread-safe collections (such as ArrayList) require external synchronization. Java provides mechanisms such as locks, atomic operations, ConcurrentHashMap, and CopyOnWriteArrayList to control concurrency, thereby ensuring data integrity and consistency in a multi-threaded environment.

How to ensure thread safety of volatile variables in Java functions? How to ensure thread safety of volatile variables in Java functions? May 04, 2024 am 10:15 AM

Methods for ensuring thread safety of volatile variables in Java: Visibility: Ensure that modifications to volatile variables by one thread are immediately visible to other threads. Atomicity: Ensure that certain operations on volatile variables (such as writing, reading, and comparison exchanges) are indivisible and will not be interrupted by other threads.

How to configure and optimize FastCGI in Nginx How to configure and optimize FastCGI in Nginx May 21, 2023 am 08:16 AM

fastcgi: fastcgi is developed and improved from cgi. The main disadvantage of the traditional cgi interface method is poor performance, because every time the http server encounters a dynamic program, the script parser needs to be restarted to perform parsing, and then the results are returned to the http server. This is almost unavailable when dealing with high concurrent access. In addition, the traditional cgi interface method has poor security and is rarely used now. The fastcgi interface mode adopts the c/s structure, which can separate the http server and the script parsing server, and start one or more script parsing daemons on the script parsing server. Every time the http server encounters a dynamic program, it can be delivered directly to fastcg

Common concurrent collections and thread safety issues in C# Common concurrent collections and thread safety issues in C# Oct 09, 2023 pm 10:49 PM

Common concurrent collections and thread safety issues in C# In C# programming, handling concurrent operations is a very common requirement. Thread safety issues arise when multiple threads access and modify the same data at the same time. In order to solve this problem, C# provides some concurrent collection and thread safety mechanisms. This article will introduce common concurrent collections in C# and how to deal with thread safety issues, and give specific code examples. Concurrent collection 1.1ConcurrentDictionaryConcurrentDictio

Thread safety and memory leaks in C++ Thread safety and memory leaks in C++ Jun 03, 2024 pm 03:52 PM

Thread safety and memory leaks in C++ In a multi-threaded environment, thread safety and memory leaks are crucial. Thread safety means that a data structure or function can be safely accessed in a concurrent environment, requiring the use of appropriate synchronization mechanisms. A memory leak occurs when allocated memory is not released, causing the program to occupy more and more memory. To prevent memory leaks, these best practices should be followed: Use smart pointers such as std::unique_ptr and std::shared_ptr to manage dynamic memory. Using RAII technology, resources are allocated when the object is created and released when the object is destroyed. Review code to identify potential memory leaks and use tools like Valgrind to detect leaks.

Multithreading in PHP Multithreading in PHP May 23, 2023 pm 08:31 PM

In PHP programming, multi-threading is a very important programming technique if we need to perform multiple tasks or handle multiple requests at the same time. Multi-threading can enable multiple threads to run at the same time, improving program efficiency and user experience. 1. Introduction to PHP multi-threading PHP multi-threading refers to a program that executes two or more threads at the same time. Each thread is an independent sub-process and can perform tasks independently. In PHP, multithreading can be handled through the pcntl extension. The pcntl extension is a process control extension supported by PHP

See all articles