Does PHP have a configuration or a way to turn thread-safe mode on?
When you run multiple scripts, you are using file locks to control parallelism, what better way to get multiple PHP scripts to communicate?
Is there any way to ensure that the PHP script is running in a thread-safe manner?
Reply content:
Does PHP have a configuration or a way to turn thread-safe mode on?
When you run multiple scripts, you are using file locks to control parallelism, what better way to get multiple PHP scripts to communicate?
Is there any way to ensure that the PHP script is running in a thread-safe manner?
So explain the question:
1. One-process single-threaded: A person eats food on a table.
2. Single-process Multithreading: Many people eat food together on the same table.
3. Multi-process Single-threaded: More than one person eats vegetables on their own table.
Multi-threaded problem is that many people at the same time eat a dish when prone to scramble, for example, two person at the same time clip a dish, a person just out of chopsticks, the results reached the time has been clip away vegetables ... At this point, you have to wait for a person to take a bite, in return to another person to the dish, that is, the sharing of resources will conflict.
1. For Windows systems, the "open table" is expensive, so Windows encourages everyone to eat on a table. Therefore, the focus of Windows multithreaded learning is to face the problem of resource scrambling and synchronization.
2. For Linux systems, the "open table" is very inexpensive, so Linux encourages everyone to open their own table for food. This brings a new problem: sitting on two different desks, it's inconvenient to talk. Therefore, the learning focus of Linux is to learn the methods of inter-process communication.
--
Add: Someone is interested in the cost of opening the table. I'll put the question to the point of extension.
Opening a table means creating a process. The overhead here mainly refers to the time overhead.
You can do an experiment: Create a process, write some data to memory in the process, read the data, and then exit. This process repeats 1000 times, which is equivalent to creating/destroying the process 1000 times. The test results on my machine are:
Ubuntulinux: 0.8 seconds
Windows7:79.8 seconds
The cost of the two is about 100 times times the difference.
This means that in Windows, the overhead of process creation cannot be overlooked. In other words, it is not recommended that you create a process in Windows programming, and if your program architecture requires a lot of process creation, it is best to switch to a Linux system.
A typical example of a large number of creation processes is two, one of which is the GNU Autotools Toolchain, which compiles a lot of open source code that is slow to compile under windows, so it's best for software developers to avoid windows. The other is the server, some server frameworks rely on a lot of creation process to work, even for each user request to create a process, these servers run under Windows is inefficient. This "possible" is also the reason why Linux servers are much larger than Windows servers worldwide.
From: http://www.zhihu.com/question/1990176 ...
It is OK to specify the relevant parameters when recompiling PHP.
Add--enable-maintainer-zts when Configure
PHP can directly call the Linux semaphore function sem_get
, complete lock, but not recommended, so compatibility is not good.