aalfiann/event-locker-php

Event Locker class to stop multiple or parallel execution in PHP.

1.0.0 2019-04-20 06:47 UTC

This package is auto-updated.

Last update: 2024-11-20 19:52:03 UTC


README

Version Total Downloads License

A Event Locker class to stop multiple or parallel execution in PHP.

Installation

Install this package via Composer.

composer require "aalfiann/event-locker-php:^1.0"

How to use

use aalfiann\EventLocker;
require_once ('vendor/autoload.php');

$locker = new EventLocker();

// lock
echo "Waiting...\n";
$locker->lock();

// sleep for 10 seconds
echo "Sleeping...\n";
sleep(10);
echo "Finished!\n";

// unlock
$locker->unlock();

You can set your custom locker name. Default is locker.lock.

// Example if you want to set identify locker for post.
$locker = new EventLocker('post.lock');