Take the 2-minute tour ×

I need mutual exclusion for some operation. On my server I have APC installed.

Is there any approved Class to acquire and release a mutex ? I would avoid to reinvent the wheel if there is already an "official" solution.

Please note, I know I could use flock, but I don't want to fall back to file system to acquire a mutex

Something like:

$m = new Mutex;
  //> Do stuff
share|improve this question
This has been answered before: stackoverflow.com/questions/2921469/php-mutual-exclusion-mutex –  Mr. Llama Dec 11 '12 at 21:50
I upvoted that question. But the answer doesn't answer this. (he uses sem) –  dynamic Dec 11 '12 at 21:58

2 Answers 2

up vote 1 down vote accepted

Later versions of PHP have a Mutex class built-in. If you are on a *nix system, also look for the "Semaphore Functions" in the documentation.

share|improve this answer
I wouldn't use sempahore. I only need Mutex. Could you post an example of Mutex class? Doc is pretty vague –  dynamic Dec 11 '12 at 21:59

You might want to try my Mutex implementation in php. It supports several adapters - flock, memcache, mysql. There is currently no apc implementation as there is no way to use it across multiple web servers - but you might always easily add it and send pull request.


share|improve this answer

Your Answer


