All Projects → arvenil → Ninja Mutex

arvenil / Ninja Mutex

Licence: mit
Mutex implementation for PHP

Projects that are alternatives of or similar to Ninja Mutex

Oneinstack
OneinStack - A PHP/JAVA Deployment Tool
Stars: ✭ 1,983 (+1001.67%)
Mutual labels:  mysql, redis, memcached
Phalcon Vm
Vagrant configuration for PHP7, Phalcon 3.x and Zephir development.
Stars: ✭ 43 (-76.11%)
Mutual labels:  mysql, redis, memcache
Zxw.framework.netcore
基于EF Core的Code First模式的DotNetCore快速开发框架,其中包括DBContext、IOC组件autofac和AspectCore.Injector、代码生成器(也支持DB First)、基于AspectCore的memcache和Redis缓存组件,以及基于ICanPay的支付库和一些日常用的方法和扩展,比如批量插入、更新、删除以及触发器支持,当然还有demo。欢迎提交各种建议、意见和pr~
Stars: ✭ 691 (+283.89%)
Mutual labels:  mysql, redis, memcached
Javainterview
java中高级基础指南
Stars: ✭ 222 (+23.33%)
Mutual labels:  lock, mysql, redis
Zebra database
A compact, lightweight and feature-rich PHP MySQLi database wrapper
Stars: ✭ 98 (-45.56%)
Mutual labels:  mysql, redis, memcache
Dotnetguide
🦸【C#/.NET/.NET Core学习、工作、面试指南】概述:C#/.NET/.NET Core基础知识,学习资料、文章、书籍,社区组织,工具和常见的面试题总结。以及面试时需要注意的事项和优秀简历编写技巧,希望能和大家一起成长进步👊。【让现在的自己不再迷漫✨】
Stars: ✭ 308 (+71.11%)
Mutual labels:  mysql, redis, memcached
Drupal Nginx Php Kubernetes
Demonstration of a set of NGINX and PHP-FPM containers running Drupal deployed to Kubernetes on the IBM Container Service. This is a work in progress.
Stars: ✭ 43 (-76.11%)
Mutual labels:  mysql, redis, memcached
Lnmp
LEMP stack/LAMP stack/LNMP stack installation scripts for CentOS/Redhat Debian and Ubuntu
Stars: ✭ 2,488 (+1282.22%)
Mutual labels:  mysql, redis, memcached
Gopherus
This tool generates gopher link for exploiting SSRF and gaining RCE in various servers
Stars: ✭ 1,258 (+598.89%)
Mutual labels:  mysql, redis, memcache
Butterfly
🔥 蝴蝶--【简单】【稳定】【好用】的 Python web 框架🦋 除 Python 2.7,无其他依赖; 🦋 butterfly 是一个 RPC 风格 web 框架,同时也是微服务框架,自带消息队列通信机制实现分布式
Stars: ✭ 82 (-54.44%)
Mutual labels:  mysql, redis, memcached
Zapi
基于swoole的异步轻量级api框架,内部封装全套mysql、redis、mongo、memcached异步客户端,可以轻松start、reload、stop,加入数据库的查询模块,框架已经封装好近乎同步写法,底层异步调用。现已支持异步mysql、异步redis、异步http请求.
Stars: ✭ 245 (+36.11%)
Mutual labels:  mysql, redis, memcached
Overlord
Overlord是哔哩哔哩基于Go语言编写的memcache和redis&cluster的代理及集群管理功能,致力于提供自动化高可用的缓存服务解决方案。
Stars: ✭ 1,884 (+946.67%)
Mutual labels:  redis, memcached, memcache
Hfish
安全、可靠、简单、免费的企业级蜜罐
Stars: ✭ 2,977 (+1553.89%)
Mutual labels:  mysql, redis, memcache
Gnomock
Test your code without writing mocks with ephemeral Docker containers 📦 Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code 💻
Stars: ✭ 398 (+121.11%)
Mutual labels:  mysql, redis, memcached
Flipper
🐬 Beautiful, performant feature flags for Ruby.
Stars: ✭ 2,732 (+1417.78%)
Mutual labels:  mysql, redis, memcached
Netkiller.github.io
Netkiller Free ebook - 免费电子书
Stars: ✭ 861 (+378.33%)
Mutual labels:  mysql, redis, memcached
Finagle
A fault tolerant, protocol-agnostic RPC system
Stars: ✭ 8,126 (+4414.44%)
Mutual labels:  mysql, redis, memcached
Mdserver Mac
mdserver (mac version, secondary development)
Stars: ✭ 121 (-32.78%)
Mutual labels:  mysql, redis, memcached
Zhttp
基于swoole的异步轻量级web框架,内部封装协程异步非阻塞全套mysql、redis、mongo、memcached连接池,可以轻松start、reload、stop,加入数据库的查询模块,框架已经封装好近乎同步写法,底层异步调用
Stars: ✭ 131 (-27.22%)
Mutual labels:  mysql, redis, memcached
Spring Boot Vue Bank
我,请始皇[打钱]是一个前后端分离的工具人系统,项目采用 SpringBoot+Go+Vue 开发,项目加入常见的企业级应用所涉及到的技术点,例如 Redis、RabbitMQ 等(主要是多用用工具多踩踩坑)。
Stars: ✭ 157 (-12.78%)
Mutual labels:  mysql, redis

License PHP Version

Build

Coverage Quality Maintainability Grade Total Downloads

About

ninja-mutex is a simple to use mutex implementation for php. It supports different adapters (flock, memcache, mysql, redis, ...) so you can set it up as you wish. All adapters (if set up properly) can be used in multi server environment - in other words lock is shared between web servers.

Usage

Mutex

First you need to choose an adapter and setup it properly. For example if you choose flock implementation first you need to set up NFS filesystem and mount it on web servers. In this example we will choose memcache adapter:

<?php
require 'vendor/autoload.php';

use NinjaMutex\Lock\MemcacheLock;
use NinjaMutex\Mutex;

$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11211);
$lock = new MemcacheLock($memcache);
$mutex = new Mutex('very-critical-stuff', $lock);
if ($mutex->acquireLock(1000)) {
    // Do some very critical stuff

    // and release lock after you finish
    $mutex->releaseLock();
} else {
    throw new Exception('Unable to gain lock!');
}

Mutex Fabric

If you want to use multiple mutexes in your project then MutexFabric is the right solution. Set up lock implementor once, and you can use as many mutexes as you want!

<?php
require 'vendor/autoload.php';

use NinjaMutex\Lock\MemcacheLock;
use NinjaMutex\MutexFabric;

$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11211);
$lock = new MemcacheLock($memcache);
$mutexFabric = new MutexFabric('memcache', $lock);
if ($mutexFabric->get('very-critical-stuff')->acquireLock(1000)) {
    // Do some very critical stuff

    // and release lock after you finish
    $mutexFabric->get('very-critical-stuff')->releaseLock();
} else {
    throw new Exception('Unable to gain lock for very critical stuff!');
}

if ($mutexFabric->get('also-very-critical-stuff')->acquireLock(0)) {
    // Do some also very critical stuff

    // and release lock after you finish
    $mutexFabric->get('also-very-critical-stuff')->releaseLock();
} else {
    throw new Exception('Unable to gain lock for also very critical stuff!');
}

Installation

Composer

Download composer:

wget -nc http://getcomposer.org/composer.phar

Add dependency to your project:

php composer.phar require arvenil/ninja-mutex:*

Running tests

Tests require vfsStream to work. To install it, simply run in project dir:

wget -nc http://getcomposer.org/composer.phar && php composer.phar install --dev

To run tests type in a console:

vendor/bin/phpunit

Something doesn't work

Feel free to fork project, fix bugs and finally request for pull

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].