PHP does not have perfect threading support, and even deploying to a threading model-based HTTPD server can have some problems, but even PHP under a multi-process model will inevitably have multiple processes with common access to the same resource. For example, the entire program shared data cache, or because of resource constraints must be queued for specific processes, and for each user to generate a unique identity of a situation. The PHP language itself does not provide process mutexes and locking mechanisms, which makes programming in these situations difficult, and the options currently available are the following:
Use MySQL's locking mechanism to achieve mutual exclusion. The disadvantage is that it increases the connection burden on the database server and makes the program dependent on the database service to work properly.
Use the file lock mechanism. That is, using the flock function to implement locking and mutual exclusion mechanisms through the file, to simulate the common programming model of the locking primitive working mode. This approach, which previously served as a storage engine for plain text files, became a necessary element in preserving data integrity, and is now quite common in situations where text files are used as cache media. PmWiki should also use this mechanism to remind multiple people to edit a page at the same time. However, the file lock mechanism will call the file Lock feature on the host operating system, so it is necessary to check whether the server operating system provides a perfect and reliable file lock mechanism for the PHP environment.
Use the shared memory space count. PHP can use the Shmop_open function to open up a piece of memory space, sharing data between service processes, in order to ensure mutually exclusive secure access to shared data, you can use the Sem_get, Sem_acquire and sem_release This set of functions to implement a shared count locking mechanism. This approach in the background is actually called the system's IPC service to achieve.