takuya/php-sharedmemory-keystore

0.1 2025-03-09 16:53 UTC

This package is auto-updated.

Last update: 2025-03-11 10:32: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()

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 code.

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 @