Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP shared memory: shm vs shmop vs SyncSharedMemory

Tags:

php

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?

like image 588
Roland Seuhs Avatar asked Aug 23 '26 21:08

Roland Seuhs


1 Answers

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.

like image 183
MThiele Avatar answered Aug 26 '26 10:08

MThiele



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!