This article mainly introduces the concept of understanding the PHP shared memory and advantages and disadvantages, has a certain reference value, now share to everyone, the need for friends can refer to
Shared memory is an efficient way to share and pass data between two running processes in the same machine, and the memory shared between different processes is usually scheduled as the same piece of physical memory; By definition, shared memory allows two unrelated processes to access the same logical memory. A process can create a memory segment that can be accessed by other processes as long as it is assigned the correct permissions. Each memory segment has a unique ID (called Shmid), which points to a physical memory area where other processes can manipulate it. Once the appropriate permissions have been created and provided, other processes in the same machine can manipulate these memory segments: read, write, and delete, and if a process writes data to shared memory, the changes will immediately affect any other processes that can access the same piece of shared memory.
This means that applications written in C can share information with applications written in other languages, such as Java or PHP. There is widespread use of implementations within a share for most languages, so access should not be a problem. To understand information, we can use a standard format, such as XML or JSON.
The use of shared memory is a quick way to exchange data between processes, primarily because the data is passed after the memory segment is created and does not involve the kernel. This approach is often referred to as interprocess communication (IPC). Other IPC methods include pipelines, Message Queuing, RPC, and sockets. This ability to exchange data quickly and reliably between applications is useful when using an ecosystem of applications that need to communicate with each other. Depending on the size of the ecosystem, common ways to use databases to exchange information between applications often result in slow queries and even I/O blocking. With shared memory, no I/O slows developers ' progress.
Shared memory does not provide a synchronization mechanism, that is, there is no automatic mechanism to prevent the second process from starting to read the shared memory until the first process ends the write operation. So we usually need to use other mechanisms to synchronize access to shared memory.
The proposal in this article is simple enough to learn how to use PHP to create and manipulate shared memory segments, using them to store datasets that can be used by other applications. Even without a plan to exchange data using shared memory, it itself has many benefits, because it enables applications to stay away from I/O problems. storing datasets directly in memory has many advantages, from WEB service data caching to session sharing. It's a very useful concept that every PHP developer should know.
Advantages and disadvantages of using shared memory
1, advantages: we can see the use of shared memory for interprocess communication is really convenient, and the interface of the function is also simple, data sharing also makes the data between processes not to transmit, but directly access memory, but also speed up the efficiency of the program. At the same time, it does not require a certain parent-child relationship as the process of communicating with anonymous pipelines.
2, Disadvantage: Shared memory does not provide a mechanism for synchronization, which allows us to use shared memory for interprocess communication, often with the help of other means of synchronization between processes.
We can use shared memory as a unique storage option, providing the benefits of fast read/write operations and process interoperability. For a WEB application, this means:
Cache Storage (Database queries, WEB service data, external data)
Session Store
Exchange of data between applications
This storage technology is useful not only for caching, but also for exchanging data between applications, as long as the data is stored in a format that is readable at both ends. Do not underestimate the power of WEB applications that exist within a share. This kind of storage can be cleverly implemented in many different ways, with the only limitation being the developer's creativity and skills.
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!