简体   繁体   中英

PHP shared memory: shm vs shmop vs SyncSharedMemory

In PHP, there are different extensions available for shared memory:

shm, part of the "Semaphore" extension in the docs that uses system V IPC functions:

https://www.php.net/manual/en/intro.sem.php

And shmop, a PHP-native extension:

https://www.php.net/manual/en/intro.shmop.php

The docs are very slim, so far I have found just these differences:

  • SysV-Shared memory allows usage from non-PHP programs
  • SysV-Shared memory is not available on Windows

Since we for sure will never use Windows as a server and also have a couple of C-based programs which may benefit from shared memory access, I would prefer Sys-V based shared memory.

Edit: I just discovered a third one: The SyncSharedMemory class in the "sync" extension.

Are there any performance differences between these three extensions [ shmop, SyncSharedMemory, SysV-Shared memory ] and/or are there any other notable differences between them?

TL;DR nope

In terms of performance you are already on the safe side with the standard Shared Memomry libraries. The question is how to monitor the memory and check for changes. Just using the library should not get in the way of your performance.

For most purposes the standard way shmop is sufficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM