= self::MAX_LEN_LOCK_NAME) { //convert ot prefix and md5 full length $id = mb_substr($id, 0, 32) . md5($id); } $this->id = $id; } public function setLock() { Db::fetchOne('SELECT GET_LOCK(?,?)', array($this->id, self::MAX_LOCK_TIME)); } public function unLock() { Db::query('DO RELEASE_LOCK(?)', array($this->id)); } public function getId() { return $this->id; } /** * @description check if the lock is available to user * @param string $key * @return bool * @throws \Exception */ public static function isLockAvailable($key) { return (bool)Db::fetchOne('SELECT IS_FREE_LOCK(?)', [$key]); } }