. * * Consult LICENSE file for details ************************************************/ class SimpleMutex { private $file; private $fp; public function __construct($file = __FILE__) { $this->file = $file; } /** * Blocks the mutex * Method blocks until mutex is available! * ATTENTION: make sure that you *always* release a blocked mutex! * * @access public * @return boolean */ public function Block() { $this->fp = fopen($this->file, 'r'); return flock($this->fp, LOCK_EX); } /** * Releases the mutex * After the release other processes are able to block the mutex themselfs * * @access public * @return boolean */ public function Release() { return flock($this->fp, LOCK_UN) && fclose($this->fp) && $this->fp = null; } }