* variables. * * This demo shows you: * - why you should use mutexes * - how to use mutex-style locks with Sync * * Should be run using PHP Cli */ require "../src/Fuz/Component/SharedMemory/SharedMemory.php"; require "../src/Fuz/Component/SharedMemory/Entity/StoredEntity.php"; require "../src/Fuz/Component/SharedMemory/Storage/StorageInterface.php"; require "../src/Fuz/Component/SharedMemory/Storage/StorageFile.php"; use Fuz\Component\SharedMemory\SharedMemory; use Fuz\Component\SharedMemory\Storage\StorageFile; $storage = new StorageFile('/tmp/demo.sync'); $shared = new SharedMemory($storage); // Master process (the one you launched) if (isset($argv[1]) === false) { $shared->withoutMutexAlreadyCalculated = false; $shared->withoutMutex = 1; $shared->withMutexAlreadyCalculated = false; $shared->withMutex = 1; // Execute 5 daemons // see http://stackoverflow.com/questions/12341421 $command = sprintf("/usr/bin/php %s demo > /dev/null 2>&1 &", escapeshellarg($argv[0])); exec($command); exec($command); exec($command); exec($command); exec($command); // Wait for all daemons to end
public function testDestroyStorage() { $file = self::DIR . "/test.sync"; $storage = new StorageFile($file); $shared = new SharedMemory($storage); $shared->hello = 'world'; $this->assertTrue(file_exists($file)); $shared->destroyStorage(); $this->assertFalse(file_exists($file)); $shared->hello = 'world'; $this->assertTrue(file_exists($file)); $shared->destroyStorage(); $this->assertFalse(file_exists($file)); }