PHP code example of ninsuo / php-shared-memory

1. Go to this page and download the library: Download ninsuo/php-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/ */

    

ninsuo / php-shared-memory example snippets




use Fuz\Component\SharedMemory\Storage\StorageFile;
use Fuz\Component\SharedMemory\SharedMemory;

// On both apps
$storage = new StorageFile('/tmp/demo.sync');

// First app
$sharedA = new SharedMemory($storage);
$sharedA->foo = 'bar';

// Second app
$sharedB = new SharedMemory($storage);
echo $sharedB->foo; // bar




uz\Component\SharedMemory\SharedMemory;
use Fuz\Component\SharedMemory\Storage\StorageFile;

$storage = new StorageFile('/tmp/demo.sync');
$shared = new SharedMemory($storage);

if (isset($argv[1]) === false)
{
    // master process (the one you launched)
    $shared->hello = "foo, bar!\n";

    $command = sprintf("/usr/bin/php %s demo", escapeshellarg($argv[0]));
    exec($command);

    echo $shared->hello;
}
else
{
    // child process
    $shared->hello = "Hello, world!\n";
}

// $ php demo/Sync.demo.1.php
// Hello, world!
// $

json
{
    "insuo/php-shared-memory": "dev-master"
    }
}