{"id":158799,"date":"2012-11-28T09:01:03","date_gmt":"2012-11-28T05:01:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=158799"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=158799","title":{"rendered":"<span class=\"post_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f Lock\u2019\u043e\u0432 \u043d\u0430 \u0441\u0430\u0439\u0442\u0430\u0445 Alawar<\/span>"},"content":{"rendered":"<div class=\"content html_format\">\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u0445 \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u043c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0435 \u0440\u0430\u0437 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<p>  \u0427\u0430\u0441\u0442\u043e \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0445\u0435\u043c\u0430 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0444\u0430\u043a\u0442 \u0437\u0430\u043d\u044f\u0442\u043e\u0441\u0442\u0438 \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432. \u0421\u0440\u0435\u0434\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c:  <\/p>\n<ul>\n<li>\u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 100% \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432;<\/li>\n<li>\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430;<\/li>\n<li>\u0438 \u0441\u0430\u043c\u043e\u0435 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435&nbsp;&ndash; \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0435\u0451 \u043d\u0435 \u0441\u043d\u044f\u043b, \u0442\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0442\u0430\u043a \u0438 \u043d\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0443, \u043f\u043e\u043a\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u043b\u0438 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u044d\u0442\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043d\u044f\u0442\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u044b \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438?<\/h4>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043d\u044b\u0435, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043e\u043d\u0438 \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044e \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443?<\/h4>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b <a href=\"http:\/\/ru.wikipedia.org\/wiki\/%D0%90%D1%82%D0%BE%D0%BC%D0%B0%D1%80%D0%BD%D0%B0%D1%8F_%D0%BE%D0%BF%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F\">\u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/a> \u0438 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/%D0%A2%D1%80%D0%B0%D0%BD%D0%B7%D0%B0%D0%BA%D1%86%D0%B8%D1%8F_%28%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%29\">\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u043e\u043d\u043d\u043e\u0441\u0442\u0438<\/a>. \u0418\u0445 \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0442.\u043a. \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0435\u0441\u0442\u044c \u0443\u0436\u0435 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0430 \u044d\u0442\u0438 \u0442\u0435\u043c\u044b.<\/p>\n<p>  \u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438:  <\/p>\n<ul>\n<li>\u0432\u0437\u044f\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f<\/li>\n<li>\u0441\u043d\u044f\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f<\/li>\n<li>\u043f\u0440\u043e\u0434\u043b\u0438\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443<\/li>\n<li>\u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0435\u0439\u0441 \u043a\u043e\u0433\u0434\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d\u0430<\/li>\n<\/ul>\n<p>  \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a, \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438 \u0444\u0430\u0439\u043b\u044b, \u0438 mysql, \u0438 memcache, \u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0432\u0430\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442.<\/p>\n<p>  \u041d\u0430\u043c \u0431\u044b\u043b \u0431\u043b\u0438\u0436\u0435 Redis, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0441\u0432\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435, \u043d\u0430 Redis-\u0435.<\/p>\n<h4>\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u043d\u044b \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0443 \u043d\u0430\u0441<\/h4>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0430\u043c \u043d\u0430\u0448\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u00ab\u043a\u0430\u043a \u0435\u0441\u0442\u044c\u00bb \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u043f\u043e\u0447\u0442\u0438 \u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  \u041d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 Yii \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a Redis \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Rediska. \u041d\u043e \u0437\u0430\u0432\u044f\u0437\u043a\u0430 \u043d\u0430 Yii, \u043a\u0430\u043a \u0438 \u043d\u0430 Rediska, \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043d\u0430 PHP.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443:<\/p>\n<h5>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438<\/h5>\n<pre><code class=\"php\">&lt;?php \/**  * \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a  *  *\/ class Lock { \t\/** \t * \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043b\u044e\u0447 \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \t * \t * @param string $key \t * @return string \t *\/ \tstatic protected function getKey( $key ) \t{ \t\treturn $key; \t}  \t\/** \t * \u0421\u043e\u043e\u0431\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0434\u0435\u043b\u0430\u043b \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \t * \t * @param string $key - \u043a\u043b\u044e\u0447 \u043b\u043e\u043a\u0430 \t * @param float $timeWait - \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043d\u0430 \u0437\u0430\u0445\u0432\u0430\u0442 \u043b\u043e\u043a\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @param float $maxExecuteTime - \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @return bool \t *\/ \tstatic public function getLock( $key, $timeWait = 0, $maxExecuteTime = 3600 ) \t{ \t\tthrow new Lock_Exception('Not defined method getLock'); \t\treturn false; \t}  \t\/** \t * \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043a\u0440\u043e\u0441\u0441-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e \t * \t * @return string \t *\/ \tstatic protected function getCurrentProcessId() \t{ \t\tstatic $myProcessId = false;  \t\tif ( $myProcessId === false ) \t\t{ \t\t\t$uname = posix_uname(); \t\t\t$mypid = getmypid(); \t\t\t$myProcessId = $uname['nodename'] . '_' . $mypid; \t\t}  \t\treturn $myProcessId; \t}  \t\/** \t * \u0421\u043d\u044f\u0442\u0438\u0435 \u043b\u043e\u043a\u0430 \t * \t * @param string $key - \u043a\u043b\u044e\u0447 \u043b\u043e\u043a\u0430 \t * @param float $delayAfter - \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u043d\u044f\u0442\u0438\u044f \u043b\u043e\u043a\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @return bool \t *\/ \tstatic public function releaseLock( $key, $delayAfter = 0 ) \t{ \t\tthrow new Lock_Exception('Not defined method releaseLock'); \t\treturn false; \t}  \t\/** \t * \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0440\u043e\u0434\u043b\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043b\u043e\u043a\u0430 \t * \t * @param string $key - \u043a\u043b\u044e\u0447 \u043b\u043e\u043a\u0430 \t * @param float $timeProlongate - \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0434\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @return bool - \u0435\u0441\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f false, \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u0440\u043e\u0434\u043b\u0438\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \t *\/ \tstatic public function prolongate( $key, $timeProlongate ) \t{ \t\tthrow new Lock_Exception('Not defined method prolongate'); \t\treturn false; \t} }  class Lock_Exception extends Exception {  } class Timeout_Lock_Exception extends Lock_Exception {  } class LostLock_Timeout_Lock_Exception extends Timeout_Lock_Exception {  } <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041a\u043b\u0430\u0441\u0441 RedisLock<\/h5>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Redis:  <\/p>\n<pre><code class=\"php\">&lt;?php \/**  * \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043e\u043a \u043d\u0430 \u0431\u0430\u0437\u0435 Redis  *  *\/ class RedisLock extends Lock { \t\/** \t * \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043a\u043b\u044e\u0447 \u0432 noSQL \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \t * \t * @param string $key \t * @return string \t *\/ \tstatic protected function getKey( $key ) \t{ \t\t\/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 lock@ \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \t\treturn 'lock@'.$key; \t}  \t\/** \t * \u0421\u043e\u043e\u0431\u0449\u0430\u0435\u0442 true, \u0435\u0441\u043b\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0434\u0435\u043b\u0430\u043b \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \t * \t * @param string $key - \u043a\u043b\u044e\u0447 \u043b\u043e\u043a\u0430 \t * @param float $timeWait - \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043d\u0430 \u0437\u0430\u0445\u0432\u0430\u0442 \u043b\u043e\u043a\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @param float $maxExecuteTime - \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @param integer $policy - \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \u043b\u043e\u043a\u0430:  \t * \t\t0 - \u0435\u0441\u043b\u0438 \u043b\u043e\u043a \u0437\u0430\u043d\u044f\u0442 \u043d\u0430 \u0434\u043e\u043b\u0433\u043e, \u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0435\u0433\u043e \u0431\u0440\u0430\u0442\u044c,  \t * \t\t1 - \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0435 10\u043c\u0441, \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u043b\u0441\u044f \u043b\u0438 \u043b\u043e\u043a \t * @return bool \t *\/ \tstatic public function getLock( $key, $timeWait = 0, $maxExecuteTime = 3600, $policy = 0 ) \t{ \t\t\/** \t\t * \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043b\u043e\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0435\u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c \t\t *\/ \t\t$timeStop = microtime(true) + $timeWait;  \t\t\/\/ \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Yii \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Redis \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Rediska \t\t$rediska = Yii::app()-&gt;rediskaConnection-&gt;connect();  \t\twhile ( true ) \t\t{ \t\t\t$currentTime = microtime(true);  \t\t\tif ( $policy == 0 ) \t\t\t{ \t\t\t\t\/** \t\t\t\t * \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043b\u043e\u043a \t\t\t\t *\/ \t\t\t\t$expireAt = $rediska-&gt;getFromHash( self::getKey($key), 'expireAt' );  \t\t\t\t\/** \t\t\t\t * \u0435\u0441\u043b\u0438 \u0432\u0440\u0435\u043c\u044f, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u044b\u043b \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043b\u043e\u043a, \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u043d\u0430\u0448\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \t\t\t\t * \u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432\u0441\u0442\u0430\u0435\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0430 \u043b\u043e\u043a\u043e\u043c \t\t\t\t *\/ \t\t\t\tif ( $expireAt &gt; $timeStop ) \t\t\t\t{ \t\t\t\t\treturn false; \t\t\t\t} \t\t\t\t\/** \t\t\t\t * \u0438\u043d\u0430\u0447\u0435 \u0435\u0441\u043b\u0438 \u043d\u0430\u0434\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c, \u0442\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0451\u043c \u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u043b\u043e\u043a \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u0441\u044f \t\t\t\t *\/ \t\t\t\telseif ( $expireAt &gt; $currentTime ) \t\t\t\t{ \t\t\t\t\tusleep( 1000000 * intval($expireAt - $currentTime) ); \t\t\t\t\t$currentTime = microtime(true); \t\t\t\t} \t\t\t} \t\t\telseif ( $policy == 1 ) \t\t\t{ \t\t\t\t\/** \t\t\t\t * \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043b\u043e\u043a \t\t\t\t *\/ \t\t\t\t$expireAt = $rediska-&gt;getFromHash( self::getKey($key), 'expireAt' );  \t\t\t\twhile ( $expireAt &gt; $timeStop || $expireAt &gt; $currentTime ) \t\t\t\t{ \t\t\t\t\tusleep( 10000 );  \t\t\t\t\t\/** \t\t\t\t\t * \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043b\u043e\u043a \t\t\t\t\t *\/ \t\t\t\t\t$expireAt = $rediska-&gt;getFromHash( self::getKey($key), 'expireAt' );  \t\t\t\t\t$currentTime = microtime(true);  \t\t\t\t\tif ( $currentTime &gt;= $timeStop ) \t\t\t\t\t{ \t\t\t\t\t\treturn false; \t\t\t\t\t} \t\t\t\t} \t\t\t}  \t\t\t$getLock = false;  \t\t\t\/** \t\t\t * \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0441\u0442\u0430\u0440\u044b\u0439 \u043b\u043e\u043a \t\t\t * \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f getConnectionByKeyName \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u0442\u0435\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 Redis \t\t\t *\/ \t\t\t$transaction = $rediska-&gt;transaction( $rediska-&gt;getConnectionByKeyName( self::getKey($key) ) ); \t\t\t$transaction-&gt;watch( self::getKey($key) );  \t\t\t$arData = $rediska-&gt;getHash( self::getKey($key) ); \t\t\t\/\/ \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \t\t\t$daddy = isset($arData['daddy']) ? $arData['daddy'] : ''; \t\t\t\/\/ \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0437\u0430\u0445\u0432\u0430\u0442\u0430 \t\t\t$expireAt = isset($arData['expireAt']) ? $arData['expireAt'] : 0;  \t\t\t\/** \t\t\t * \u0435\u0441\u043b\u0438 \u043b\u043e\u043a \u043d\u0435 \u0441\u043d\u044f\u0442, \u0430 \u0432\u0440\u0435\u043c\u044f \u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438\u0441\u0442\u0435\u043a\u043b\u043e, \u0442\u043e \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u043b\u043e\u043a \t\t\t * \u0442\u0430\u043a\u0436\u0435 \u044d\u0442\u043e\u0442 \u043a\u0435\u0439\u0437 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0441\u0430\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u0440\u0430\u0437 \t\t\t *\/ \t\t\tif ( $daddy != self::getCurrentProcessId() && $expireAt &lt; $currentTime ) \t\t\t{ \t\t\t\t$transaction-&gt;setToHash( \t\t\t\t\tself::getKey($key), \t\t\t\t\tarray( \t\t\t\t\t\t'daddy' =&gt; self::getCurrentProcessId(), \t\t\t\t\t\t'expireAt' =&gt; $currentTime + $maxExecuteTime \t\t\t\t\t) \t\t\t\t); \t\t\t\t$transaction-&gt;expire( self::getKey($key), ceil($currentTime + $maxExecuteTime), true );  \t\t\t\ttry { \t\t\t\t\t$transaction-&gt;execute(); \t\t\t\t\t$getLock = 1; \t\t\t\t} \t\t\t\tcatch ( Rediska_Transaction_Exception $e ) \t\t\t\t{ \t\t\t\t\t\/** \t\t\t\t\t * \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442 \u043b\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u0435\u043b \t\t\t\t\t *\/ \t\t\t\t\t$getLock = false; \t\t\t\t} \t\t\t} \t\t\telse \t\t\t{ \t\t\t\t$getLock = false; \t\t\t\t$transaction-&gt;discard(); \t\t\t}  \t\t\t\/** \t\t\t * \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0432\u0437\u044f\u0442\u044c \u043b\u043e\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \t\t\t *\/ \t\t\tif ( $getLock != 1 ) \t\t\t{ \t\t\t\t\/\/ HSETNX \t\t\t\t$getLock = $rediska-&gt;setToHash( self::getKey($key), 'daddy', self::getCurrentProcessId(), false ); \t\t\t}  \t\t\t\/** \t\t\t * \u0435\u0441\u043b\u0438 \u043b\u043e\u043a \u043d\u0430\u0448 \t\t\t *\/ \t\t\tif ( $getLock == 1 ) \t\t\t{ \t\t\t\t\/** \t\t\t\t * \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0432\u0440\u0435\u043c\u044f, \u0434\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \t\t\t\t *\/ \t\t\t\t$rediska-&gt;setToHash(self::getKey($key),\t'expireAt', $currentTime + $maxExecuteTime); \t\t\t\t$rediska-&gt;expire(self::getKey($key), ceil($currentTime + $maxExecuteTime), true);  \t\t\t\treturn true; \t\t\t} \t\t\telse \t\t\t{ \t\t\t\t\/** \t\t\t\t * \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u0435\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u0443\u044e \u043f\u043e\u043f\u044b\u0442\u043a\u0443, \u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0435\u0451 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \t\t\t\t *\/ \t\t\t\tif ( $timeStop &gt; $currentTime ) \t\t\t\t{ \t\t\t\t\tusleep(20000); \t\t\t\t} \t\t\t\t\/** \t\t\t\t * \u0438\u043d\u0430\u0447\u0435 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u043c, \u0447\u0442\u043e \u043b\u043e\u043a\u0430 \u043d\u0435\u0442 \t\t\t\t *\/ \t\t\t\telse \t\t\t\t{ \t\t\t\t\treturn false; \t\t\t\t} \t\t\t} \t\t} \t}  \t\/** \t * \u0421\u043d\u044f\u0442\u0438\u0435 \u043b\u043e\u043a\u0430 \t * \t * @param string $key - \u043a\u043b\u044e\u0447 \u043b\u043e\u043a\u0430 \t * @param float $delayAfter - \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u0441\u043d\u044f\u0442\u0438\u044f \u043b\u043e\u043a\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @return bool \t *\/ \tstatic public function releaseLock( $key, $delayAfter = 0 ) \t{ \t\t$currentTime = microtime(true);  \t\t$rediska = Yii::app()-&gt;rediskaConnection-&gt;connect();  \t\t$transaction = $rediska-&gt;transaction( $rediska-&gt;getConnectionByKeyName( self::getKey($key) ) ); \t\t$transaction-&gt;watch( self::getKey($key) );  \t\t$arData = $rediska-&gt;getHash( self::getKey($key) ); \t\tif ( is_array($arData) && isset($arData['daddy']) && isset($arData['expireAt']) ) \t\t{ \t\t\t$daddy = $arData['daddy']; \t\t\t$expireAt = $arData['expireAt']; \t\t} \t\telse \t\t{ \t\t\t$daddy = false; \t\t\t$expireAt = 0; \t\t}  \t\t\/** \t\t * \u0415\u0441\u043b\u0438 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043b\u043e\u043a \u0431\u044b\u043b \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u044d\u0442\u0438\u043c \u0436\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c, \u0442\u043e \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043d\u044f\u0442\u044c \u043b\u043e\u043a \t\t *\/ \t\tif ( $daddy == self::getCurrentProcessId() ) \t\t{ \t\t\t$transaction-&gt;setToHash(self::getKey($key), 'expireAt', $currentTime + $delayAfter); \t\t\t$transaction-&gt;expire(self::getKey($key), ceil($currentTime + $delayAfter), true); \t\t\t$transaction-&gt;deleteFromHash( self::getKey($key), 'daddy' ); \t\t\t\/** \t\t\t * \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e \u0441\u043d\u044f\u0442\u044c \u043b\u043e\u043a \t\t\t *\/ \t\t\ttry { \t\t\t\t$transaction-&gt;execute(); \t\t\t\t$result = true; \t\t\t} \t\t\tcatch (Rediska_Transaction_Exception $e) \t\t\t{ \t\t\t\t$result = false; \t\t\t} \t\t} \t\telse \t\t{ \t\t\t$transaction-&gt;discard(); \t\t\t$result = false; \t\t}  \t\t\/\/ \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u043b\u043e\u0447\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u043e\u0437\u0436\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \t\tif ( $expireAt &lt; $currentTime ) \t\t{ \t\t\tif ( $result ) \t\t\t{ \t\t\t\t\/** \t\t\t\t * \u0432\u0441\u0451 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u043d\u043e \u043f\u0440\u043e\u0434\u043b\u0435\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u043e \u0432\u043e\u0432\u0440\u0435\u043c\u044f \t\t\t\t *\/ \t\t\t\tthrow new Timeout_Lock_Exception('Timeout Lock on release'); \t\t\t} \t\t\telse \t\t\t{ \t\t\t\t\/** \t\t\t\t * \u0437\u043d\u0430\u0447\u0438\u0442 \u043b\u043e\u043a \u0431\u044b\u043b \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \t\t\t\t *\/ \t\t\t\tthrow new LostLock_Timeout_Lock_Exception('Timeout Lock and it was lost before release'); \t\t\t} \t\t} \t\treturn $result; \t}  \t\/** \t * \u041f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u0440\u043e\u0434\u043b\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043b\u043e\u043a\u0430 \t * \t * @param string $key - \u043a\u043b\u044e\u0447 \u043b\u043e\u043a\u0430 \t * @param float $timeProlongate - \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0434\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \t * @return bool - \u0435\u0441\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f false, \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u0440\u043e\u0434\u043b\u0438\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \t *\/ \tstatic public function prolongate( $key, $timeProlongate ) \t{ \t\t$rediska = Yii::app()-&gt;rediskaConnection-&gt;connect();  \t\t$transaction = $rediska-&gt;transaction( $rediska-&gt;getConnectionByKeyName( self::getKey($key) ) ); \t\t$transaction-&gt;watch( self::getKey($key) );  \t\t$arData = $rediska-&gt;getHash( self::getKey($key) ); \t\t$daddy = $arData['daddy']; \t\t$expireAt = $arData['expireAt'];  \t\t$currentTime = microtime(true);  \t\t$result = false; \t\tif ( $daddy == self::getCurrentProcessId() ) \t\t{ \t\t\t$transaction-&gt;setToHash( self::getKey($key), 'expireAt', $currentTime + $timeProlongate ); \t\t\t$transaction-&gt;expire(self::getKey($key), ceil($currentTime + $timeProlongate), true); \t\t\ttry { \t\t\t\t$transaction-&gt;execute(); \t\t\t\t$result = true; \t\t\t} \t\t\tcatch (Rediska_Transaction_Exception $e) \t\t\t{ \t\t\t\t$result = false; \t\t\t} \t\t} \t\telse \t\t{ \t\t\t$transaction-&gt;discard(); \t\t\t$result = false; \t\t}  \t\tif ( $expireAt &lt; $currentTime ) \t\t{ \t\t\tif ( $result ) \t\t\t{ \t\t\t\tthrow new Timeout_Lock_Exception('Timeout Lock on prolongate'); \t\t\t} \t\t\telse \t\t\t{ \t\t\t\tthrow new LostLock_Timeout_Lock_Exception('Timeout Lock and Lost them on prolongate'); \t\t\t} \t\t}  \t\treturn $result; \t} } <\/code><\/pre>\n<p>  <\/p>\n<h5>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h5>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043e\u0442\u0447\u0451\u0442\u044b. \u0418 \u044d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442.\u043a. \u043e\u043d\u0438 \u0432\u0441\u0435 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u0434\u0430\u0434\u0443\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432. \u041c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u0430 40-50 \u043c\u0438\u043d\u0443\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0437\u0430\u043f\u0430\u0441 \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043d\u0430 60 \u043c\u0438\u043d\u0443\u0442.  <\/p>\n<pre><code class=\"php\">\t\t\t$lockKey = 'cron-report'; \t\t\t$timeWait = 0; \t\t\t$timeLock = 3600;  \t\t\tif ( RedisLock::getLock( $lockKey, $timeWait, $timeLock ) ) \t\t\t{ \t\t\t\t\/\/ \u043b\u043e\u043a \u0432\u0437\u044f\u043b\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c \t\t\t\t...  \t\t\t\t\/\/ \u043a\u043e\u0433\u0434\u0430 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0434\u043e\u0448\u043b\u043e \u043a \u043a\u043e\u043d\u0446\u0443 \u0438\u043b\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c, \u0442\u043e \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043d\u044f\u0442\u044c \u043b\u043e\u043a \t\t\t\ttry \t\t\t\t{ \t\t\t\t\tRedisLock::releaseLock( $lockKey, 0 ); \t\t\t\t\techo 'Ok'; \t\t\t\t} \t\t\t\tcatch ( Timeout_Lock_Exception $e ) \t\t\t\t{ \t\t\t\t\t\/\/ \u043e\u043f\u0430\u0441\u043d\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \t\t\t\t\t\/\/ \u044d\u0442\u043e\u0442 \u043a\u0435\u0439\u0441 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0435\u0441\u0443\u0440\u0441 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0435\u043c \u043e\u043d \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043e\u043d \u0435\u0449\u0451 \u043d\u0435 \u0437\u0430\u043d\u044f\u0442 \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \t\t\t\t\techo 'Timeout_Lock_Exception ' . ( $endTime - $currentTime ); \t\t\t\t} \t\t\t\tcatch ( LostLock_Timeout_Lock_Exception $e ) \t\t\t\t{ \t\t\t\t\t\/\/ \u043f\u043b\u043e\u0445\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \t\t\t\t\t\/\/ \u044d\u0442\u043e\u0442 \u043a\u0435\u0439\u0441 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0435\u0441\u0443\u0440\u0441 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0435\u043c \u043e\u043d \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0438 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043d\u044f\u0442\u0438\u044f \u043b\u043e\u043a\u0430 \u0443\u0436\u0435 \u0431\u044b\u043b \u0437\u0430\u043d\u044f\u0442 \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \t\t\t\t\techo 'LostLock_Timeout_Lock_Exception' . ( $endTime - $currentTime ); \t\t\t\t} \t\t\t} <\/code><\/pre>\n<p>  \u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u0430.<\/p>\n<p>  \u0416\u0434\u0451\u043c \u0432\u0430\u0448\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438.    \t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/company\/alawar\/blog\/158799\/\"> http:\/\/habrahabr.ru\/company\/alawar\/blog\/158799\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">\n<h4>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430\u0445 \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u043c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0435 \u0440\u0430\u0437 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<p>  \u0427\u0430\u0441\u0442\u043e \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0445\u0435\u043c\u0430 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0444\u0430\u043a\u0442 \u0437\u0430\u043d\u044f\u0442\u043e\u0441\u0442\u0438 \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u0440\u044f\u0434 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432. \u0421\u0440\u0435\u0434\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c:  <\/p>\n<ul>\n<li>\u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 100% \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432;<\/li>\n<li>\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430;<\/li>\n<li>\u0438 \u0441\u0430\u043c\u043e\u0435 \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0435&nbsp;&ndash; \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0435\u0451 \u043d\u0435 \u0441\u043d\u044f\u043b, \u0442\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0442\u0430\u043a \u0438 \u043d\u0435 \u0441\u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0443, \u043f\u043e\u043a\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438\u043b\u0438 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u044d\u0442\u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043d\u044f\u0442\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u044b \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438?<\/h4>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043d\u044b\u0435, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043e\u043d\u0438 \u0441\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044e \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-158799","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/158799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158799"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/158799\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}