PHP Classes

Hi Kamil, this is a good idea and your code is well written, ...

Recommend this page to a friend!

      Ninja Mutex  >  All threads  >  Hi Kamil, this is a good idea and...  >  (Un) Subscribe thread alerts  
Subject:Hi Kamil, this is a good idea and...
Summary:Package rating comment
Messages:2
Author:Alfredito
Date:2013-09-24 14:28:23
Update:2013-09-27 10:46:37
 

Alfredito rated this package as follows:

Utility: Sufficient
Consistency: Insufficient

  1. Hi Kamil, this is a good idea and...   Reply   Report abuse  
Picture of Alfredito Alfredito - 2013-09-24 14:28:23
Hi Kamil, this is a good idea and your code is well written, however in order to really work, a mutex need support from the operating system or from a container, because the instruction for lock and unlock the mutex needs to be atomic. I couldn't see any support from the container (web server), so it will work some times and fail some times.

  2. Re: Hi Kamil, this is a good idea and...   Reply   Report abuse  
Picture of Kamil Dziedzic Kamil Dziedzic - 2013-09-27 10:46:37 - In reply to message 1 from Alfredito
Hi

I'm not really sure if I understand your doubts.

Mutex class abstracts the way you gain lock so you don't need to play with low level stuff you need to only use ->acquireLock() and ->releaseLock() methods.

Atomic locking is done by Lock classes and Mutex can use any of them.
Currently you can choose between 5 of them which uses one of the following method: flock, memcache, mysql, redis.

Each of this class uses an atomic, locking mechanism.
FlockLock: http://php.net/manual/en/function.flock.php
Memcache{,d}Lock: http://code.google.com/p/memcached/wiki/NewCommands#add
MySqlLock: http://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_get-lock
PredisRedisLock: http://redis.io/commands/setnx

Of course each of this method has some pros and cons - and thats why I've build this class so you could always switch between methods without much effort and choose which one suits you best.

You may see some usage examples on github project page https://github.com/arvenil/ninja-mutex which may light things a little better (Can I somehow place here good help docs?).