takuya / php-sharedmemory-keystore
php shmop_xx wrapper
0.2
2025-04-29 04:34 UTC
Requires
- php: >=8.1
- ext-shmop: *
- takuya/php-sysv-ipc-semaphore: ^0.3
Requires (Dev)
- ext-pcntl: *
- phpunit/phpunit: ^10
This package is auto-updated.
Last update: 2025-05-01 10:33:03 UTC
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 @