PHP code example of takuya / php-sysv-ipc-shared-memory

1. Go to this page and download the library: Download takuya/php-sysv-ipc-shared-memory library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

takuya / php-sysv-ipc-shared-memory example snippets



$uniq_name = 'shm_name';
$shm = new IPCSharedMem($uniq_name);
$shm->put(new MyClass());
//
$obj = $shm->get();// instance of MyClass;
// remove ipc
$shm->destroy()


$idx = 'key';
$store = new IPCShmKeyStore('shm_name');
$store->runWithLock(function($store)use($idx){
  $store->set($store,$shm->get($idx)+1);
});


$store = new IPCShmKeyStore('kvs-like', 1024*1024);
// Set by key
$store->set('key',['msg'=>'Auxakai3']);
// Get by key
$store->get('key')['msg']; // => Auxakai3 


$arr = new IPCShmKeyStore('array-like', 100);
$arr[] = 'a';
$arr[] = 'b';
$arr[] = 'c';
foreach($arr as $e){
  echo "$e,";
}
// => "a,b,c,"
shell
composer 
shell
name='php-sysv-ipc-shared-memory'
composer config repositories.$name \
vcs https://github.com/takuya/$name  
composer