https://github.com/phppkg/shared-memory
shared memory operate of the php. php 共享内存操作的实现
https://github.com/phppkg/shared-memory
php-library shared-memory
Last synced: 8 months ago
JSON representation
shared memory operate of the php. php 共享内存操作的实现
- Host: GitHub
- URL: https://github.com/phppkg/shared-memory
- Owner: phppkg
- License: mit
- Created: 2017-06-03T11:47:35.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-10T09:22:14.000Z (about 7 years ago)
- Last Synced: 2024-11-30T20:22:43.189Z (over 1 year ago)
- Topics: php-library, shared-memory
- Language: PHP
- Homepage:
- Size: 23.4 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php 共享内存
[](LICENSE)
[](https://packagist.org/packages/php-comp/shm)
[](https://packagist.org/packages/php-comp/shm)
php 共享内存操作的实现。基于
- sysvshm扩展:实现system v方式的共享内存 `linux/mac`
- shmop扩展:共享内存操作扩展 `linux/mac/windows`
功能:
- 实现了共享内存的 `写入` `读取` `删除` `释放` 基本操作
- 扩展的类 `ShmMap` 实现了基于共享内存的数组结构(数组方式操作、pop/push、迭代器,读/取都会自动加锁)。
## 安装
- composer
```json
{
"require": {
"php-comp/shm": "dev-master"
}
}
```
- 直接拉取
```bash
git clone https://github.com/php-comp/shared-memory.git // github
```
## 使用
```php
use PhpComp\Shm\ShmFactory;
use PhpComp\Shm\ShmMap;
$shm = ShmFactory::make([
'key' => 1,
'size' => 512
]);
$shm->write('data string');
$ret = $shm->read();
var_dump($ret);
$shmAry = new ShmMap([
'key' => 2,
'size' => 512
]);
$shmAry['one'] = 'val1';
$shmAry['two'] = 'val2';
$shmAry->set('three', 'val3');
var_dump($shmAry['three'], $shmAry->getMap());
unset($shmAry['two']);
var_dump($shmAry->getMap());
```
## License
[MIT](LICENSE)