takuya/php-sharedmemory-keystore
最新稳定版本:0.2
Composer 安装命令:
composer require takuya/php-sharedmemory-keystore
包简介
php shmop_xx wrapper
README 文档
README
This package is wrapper for php sysv shm_xxx.
Installing
from Packagist
composer require takuya/php-sharedmemory-keystore
from GitHub
name='takuya/php-sharedmemory-keystore' repo=git@github.com:$name.git composer config repositories.$name vcs $repo composer require $name
Examples
<?php $uniq_name = 'uniq_name_for_shm' $store = new ShmArrayStore($uniq_name); $store['key']=new stdClass(); $obj = $shm->get('key');// instance of MyClass; // remove ipc $shm->destroy()
Safer access by sem
<?php $store = new ShmArrayStore('my-shm', 1024); $store->runWithLock(function($store)use($idx){ $store->set(0,($store->get(0) ?? 0)+$idx); }); }
More easy usage : Array Access.
This package offers KVS style access to Shared Memory.
<?php $store = new ShmArrayStore('kvs-like', 1024*1024); // Set by key $store->set('key',['msg'=>'Auxakai3']); // Get by key $store->get('key')['msg']; // => Auxakai3
This package has simple shmop wrapper.
<?php $shm = new ShmOperator(str_rand(), 100); $shm->put($msg); $shm->get(); $shm->erase(); $shm->isEmpty(); $shm->get(); $shm->destroy();
Limitation: ShmOperator does not have serialization;
comparison to shm_put_var
Sysv function (ex shm_put_var) has auto serialization. but shmop_write does not.
shm_put_var is very confusing when you want to add json_encode or encrypt before write.
To make use of encryption or json_encode into SharedMemory, shmop_write is better.
See Also.
I wrote these php sysv-ipc code.
- SysV IPC Wrapper
- shm_open
- PHP SharedMemory Operation (shmop_open) This package.
- psr/simplecache
- maintenance
- laravel cache
remove ipc by manually
If unused ipc remains. use SHELL command to remove.
ipcs -m | grep $USER | grep -oE '0x[a-f0-9]+' | xargs -I@ ipcrm --shmem-key @
统计信息
- 总下载量: 60
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-03-09