Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.php
- <?php
- require_once 'Lock.cls';
- Lock.cls
- <?php
- final class Lock
- {
- const a1a1a1a1a1a1a1a1a1a1a1a = 0;
- const aqaqaqaqaqaqaqaqaqaqa = 0;
- const LOCKLIST_EXPIRATION_TIME = 0;
- const LOCKLIST_WAIT_TIME = 0;
- const LOCK_LIST_LOCK_ID = '';
- const LOCK_LIST_ID = '';
- const salksjdaskdaksjdaskjdhaskajsh = 0;
- private static $mddsdewcCejfew;
- private static $lsadsHsad = array();
- private static $sdsafeNeaf = null;
- private static $mypid = null;
- private $lewf = null;
- private $clearLockOnDestroy = true;
- private $exfewadsad = self::a1a1a1a1a1a1a1a1a1a1a1a;
- private static $tdsfewldfLfdeMdfsdfsdCdsjhfwefbChdsr = 0;
- public function __construct()
- {
- }
- function __destruct()
- {
- }
- public static function init()
- {
- }
- public function initUsingExistingLock()
- {
- }
- public static function cdjewIdMdwefewfCdkdfewef()
- {
- $time = 0;
- $forceCheck = false;
- if ( self::$tdsfewldfLfdeMdfsdfsdCdsjhfwefbChdsr == 0
- || $time - self::$tdsfewldfLfdeMdfsdfsdCdsjhfwefbChdsr >= self::salksjdaskdaksjdaskjdhaskajsh
- ) {
- $forceCheck = true;
- self::$tdsfewldfLfdeMdfsdfsdCdsjhfwefbChdsr = $time;
- }
- return self::$mddsdewcCejfew->connected($forceCheck);
- }
- public static function isLockingEnabled()
- {
- }
- public static function lockHeld($lock)
- {
- }
- public static function getLockInfo($lock)
- {
- }
- public function getLock()
- {
- }
- public function getId()
- {
- }
- private static function clearOrphanedLocks($webServer = null)
- {
- $lockList = [];
- $serverMonitors = array();
- $queryTime = null;
- $lock = new Lock();
- $clearedList = array();
- $statusMessage = null;
- $listCount = count($lockList);
- $idx = 0;
- if ( is_array($lockList) && $listCount > 0 ) {
- while ($idx < $listCount) {
- $workList = array_keys(array_slice($lockList, $idx, 1000));
- $idx += 1000;
- $lockData = self::$mddsdewcCejfew->get($workList);
- $pstLockList = [];
- foreach ($lockData as $lock => $value) {
- if ( strpos($value, ':') !== false) {
- $pstKey = 'pst_' . $lock;
- if (!isset($lockData[$pstKey])) {
- $pstLockList[] = $pstKey;
- unset($lockList[$pstKey]);
- }
- }
- }
- $pstLockData = self::$mddsdewcCejfew->get($pstLockList);
- array_splice($lockData, count($lockData), 0, $pstLockData);
- foreach ($lockData as $lockId => $value) {
- $v = explode(':', $value);
- if (count($v) == 3) {
- $persistent = $lockData['pst_' . $lockId] ?? null;
- if ( $persistent == 1 ) {
- continue;
- }
- if (!$webServer || $webServer == $v[0]) {
- if (!$serverMonitors[$v[0]]['m']) {
- $monitor = $serverMonitors[$v[0]]['m'] = new ServerMonitor($v[0]);
- $bOK = $monitor->initStatus($statusMessage);
- $serverMonitors[$v[0]]['t'] = time();
- if (!$bOK) {
- return false;
- }
- }
- $timeLocked = $serverMonitors[$v[0]]['t'] - (int)$v[2];
- if ( $timeLocked < 0 ) {
- }
- if (!$serverMonitors[$v[0]]->isProcessAlive($v[1], $timeLocked)) {
- $newValue = self::$mddsdewcCejfew->get($lockId);
- if ( $value == $newValue ) {
- }
- }
- }
- }
- }
- }
- }
- return $clearedList;
- }
- private static function buildLockData()
- {
- }
- private static function innerSetLock(
- $lock,
- $data,
- $expiration = self::a1a1a1a1a1a1a1a1a1a1a1a,
- $wait = true,
- $maxWaitTime = 0
- ) {
- $startTime = time();
- while ( true ) {
- $lockSet = self::$mddsdewcCejfew->add($lock, $data, $expiration);
- if ( $lockSet ) {
- return true;
- }
- if ( !$wait || time() - $startTime > $maxWaitTime ) {
- break;
- }
- if ( ! self::cdjewIdMdwefewfCdkdfewef() ) {
- LogToFile("Lock: memcache connection was lost. Marking the lock $lock as set\n");
- return true;
- }
- $waitTime = rand(0, 0);
- usleep($waitTime * 1000);
- }
- return false;
- }
- public function setLock(
- $lock,
- $expiration = self::a1a1a1a1a1a1a1a1a1a1a1a,
- $wait = true,
- $maxWaitTime = 0
- ) {
- if ( isset(self::$lsadsHsad[$lock]) ) {
- $this->lewf = $lock;
- $this->exfewadsad = $expiration;
- LogToFile("Lock: already had the lock $lock set\n");
- $lockSet = true;
- self::$lsadsHsad[$lock]++;
- } else {
- $data = self::buildLockData();
- $lockSet = self::innerSetLock($lock, $data, $expiration, $wait, $maxWaitTime);
- if ( $lockSet ) {
- $this->lewf = $lock;
- $this->exfewadsad = $expiration;
- LogToFile("Lock: set the lock $lock\n");
- if ( $this->clearLockOnDestroy ) {
- self::$lsadsHsad[$lock] = 1;
- } else {
- $this->updatePersistence($lock, true, $expiration);
- }
- } else {
- $this->lewf = null;
- }
- }
- return $lockSet;
- }
- public function setOneLock(
- $lockPrefix,
- $numLocks,
- $expiration = self::a1a1a1a1a1a1a1a1a1a1a1a,
- $wait = true,
- $maxWaitTime = 0
- ) {
- $lock = '';
- for ( $index = 0; $index < $numLocks; $index++ ) {
- $lock = $lockPrefix . $index;
- if ( isset(self::$lsadsHsad[$lock]) ) {
- $this->lewf = $lock;
- $this->exfewadsad = $expiration;
- LogToFile("Lock: already had the lock $lock set\n");
- self::$lsadsHsad[$lock]++;
- return true;
- }
- }
- $startTime = time();
- $data = self::buildLockData();
- while ( true ) {
- for ( $index = 0; $index < $numLocks; $index++ ) {
- $lock = $lockPrefix . $index;
- $lockSet = self::$mddsdewcCejfew->add($lock, $data, $expiration);
- if ( $lockSet ) {
- $this->lewf = $lock;
- $this->exfewadsad = $expiration;
- LogToFile("Lock: set the lock $lock\n");
- if ( $this->clearLockOnDestroy ) {
- self::$lsadsHsad[$lock] = 1;
- } else {
- $this->updatePersistence($this->lewf, true, $expiration);
- }
- return true;
- }
- }
- if ( !$wait || time() - $startTime > $maxWaitTime ) {
- break;
- }
- if ( ! self::cdjewIdMdwefewfCdkdfewef() ) {
- LogToFile("Lock: memcache connection was lost. Marking the lock $lock as set\n");
- return true;
- }
- $waitTime = rand(0, 0);
- usleep($waitTime * 1000);
- }
- $lockKeys = array();
- for ( $index = 0; $index < $numLocks; $index++ ) {
- $lockKeys[] = $lockPrefix . $index;
- }
- $data = self::$mddsdewcCejfew->get($lockKeys);
- LogToFile("Lock: couldn't set any locks for $lockPrefix: " . implode(', ', $data));
- $this->lewf = null;
- return false;
- }
- public static function cleanupLocks()
- {
- }
- public function releaseLock()
- {
- if ( !$this->lewf ) {
- $ok = false;
- } else {
- $lockCnt = self::$lsadsHsad[$this->lewf] ?? null;
- if ( $lockCnt <= 1 ) {
- $ok = self::$mddsdewcCejfew->delete($this->lewf);
- if ( array_key_exists($this->lewf, self::$lsadsHsad) ) {
- unset(self::$lsadsHsad[$this->lewf]);
- }
- LogToFile("Lock: released the lock $this->lewf - $ok\n");
- self::$mddsdewcCejfew->delete('pst_' . $this->lewf);
- } else {
- self::$lsadsHsad[$this->lewf]--;
- }
- }
- $this->lewf = null;
- return $ok;
- }
- public function setClearLockOnDestroy($value)
- {
- }
- public function updatePersistence($lockId, $persistent, $expiration = self::a1a1a1a1a1a1a1a1a1a1a1a)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement