ferdous/flock-write

This is a library for File lock write operation in a single shared storage

v0.1.0-alpha 2022-01-27 16:03 UTC

This package is auto-updated.

Last update: 2024-05-27 23:09:40 UTC


README

This library is for simultaneous write on a single file with locking mechanism by PHP flock function. It uses the unix semaphore to lock the file and hence a safe application to store data in a single file shared by multiple methods.

Installation

This library is compatible with all PHP version starting from 4 to 8. Just run the following command to install.

composer require ferdous/flock-write

How to add

Add the following operations to the namespace

use Ferdous\FileLockWrite\FileOperation;
use Ferdous\FileLockWrite\LockService;

Now you are ready to add the functionality by creating the object

$lockService = new LockService();
$opObj = new FileOperation($filepath, $filename,  $lockService, $data);

Operations

  • Truncate File
    $opObj->truncateFile() 
  • Write File with Exclude Lock
    $opObj->writeDataToFileAppend() 
  • Read File with Shared Lock
    $opObj->readDataFromFile() 

Unit Tests

For checking the unit tests run

./vendor/bin/phpunit . --testdox --color