positron48 / memorystorage
Classes for storing data in shared memory
Installs: 2 056
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
- malkusch/lock: ^2.1
Requires (Dev)
- phpunit/phpunit: ^9.4
README
Library that will help you to store data in shared memory using PHP's System V shared memory functions.
Features
- Store arrays of integers in shared memory
- Thread-safe access using semaphores
- Support for multiple independent storage instances
- Automatic memory management and cleanup
- Compatible with PHP 8.0, 8.1, 8.2, and 8.3
Requirements
- PHP 8.0 or higher
- System V shared memory extension (
sysvsem
,sysvshm
) malkusch/lock
package for mutex functionality
Install
composer require positron48/memorystorage
Usage
<?php require 'vendor/autoload.php'; use MemoryStorage\ArrayMemoryStorage; // Create a storage for 3 integers $storage = new ArrayMemoryStorage('my_counter', 3); // Set data $storage->set([100, 200, 300]); // Get data $data = $storage->get(); // Returns [100, 200, 300] // Use mutex for thread-safe operations $mutex = $storage->getMutex(); $mutex->synchronized(function () use ($storage) { $current = $storage->get(); $current[0]++; $storage->set($current); }); // Clean up (removes shared memory and semaphore) $storage->remove();
Development
Running Tests Locally
- Clone the repository
- Install dependencies:
composer install
- Run tests:
composer test
Continuous Integration
The project uses GitHub Actions for CI/CD with the following workflows:
- CI: Runs tests on all supported PHP versions
- Test Matrix: Extended testing with different dependency versions and OS combinations
License
This library is licensed under the GPL-3.0-or-later license. See the LICENSE file for details.