简体   繁体   English

PHP 共享内存:shm 与 shmop 与 SyncSharedMemory

[英]PHP shared memory: shm vs shmop vs SyncSharedMemory

In PHP, there are different extensions available for shared memory:在 PHP 中,共享内存有不同的扩展可用:

shm, part of the "Semaphore" extension in the docs that uses system V IPC functions: shm,文档中使用系统 V IPC 函数的“信号量”扩展的一部分:

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

And shmop, a PHP-native extension:还有 shmop,一个 PHP 原生扩展:

https://www.php.net/manual/en/intro.shmop.php 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 共享内存允许非 PHP 程序使用
  • SysV-Shared memory is not available on Windows SysV 共享内存在 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.由于我们肯定永远不会使用 Windows 作为服务器,并且还有一些基于 C 的程序可以从共享内存访问中受益,因此我更喜欢基于 Sys-V 的共享内存。

Edit: I just discovered a third one: The SyncSharedMemory class in the "sync" extension.编辑:我刚刚发现了第三个:“同步”扩展中的 SyncSharedMemory 类。

Are there any performance differences between these three extensions [ shmop, SyncSharedMemory, SysV-Shared memory ] and/or are there any other notable differences between them?这三个扩展 [ shmop、SyncSharedMemory、SysV-Shared memory ] 之间是否存在性能差异和/或它们之间是否存在任何其他显着差异?

TL;DR nope TL;博士

In terms of performance you are already on the safe side with the standard Shared Memomry libraries.就性能而言,使用标准的 Shared Memomry 库已经很安全了。 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.对于大多数用途,标准方式 shmop 就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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