2 namespace TYPO3\CMS\Core\Locking;
17 use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
18 use TYPO3\CMS\Core\Locking\Exception\LockCreateException;
57 $path = PATH_site . self::FILE_LOCK_FOLDER;
66 if (!is_writable($path)) {
69 $this->filePath = $path .
'simple_' . md5((
string)$subject);
79 $this->loops = (int)
$loops;
80 $this->step = (int)
$step;
108 if (@unlink($this->filePath) ===
false) {
132 return self::LOCK_CAPABILITY_EXCLUSIVE | self::LOCK_CAPABILITY_NOBLOCK;
142 public function acquire($mode = self::LOCK_CAPABILITY_EXCLUSIVE)
148 if (file_exists($this->filePath)) {
149 $maxExecutionTime = (int)ini_get(
'max_execution_time');
150 $maxAge = time() - ($maxExecutionTime ?: 120);
151 if (@filectime($this->filePath) < $maxAge) {
153 @unlink($this->filePath);
160 $filePointer = @fopen($this->filePath,
'x');
161 if ($filePointer !==
false) {
162 fclose($filePointer);
167 if ($mode & self::LOCK_CAPABILITY_NOBLOCK) {
171 usleep($this->step * 1000);
174 if ($mode & self::LOCK_CAPABILITY_NOBLOCK && !$this->
isAcquired && $wouldBlock) {
196 @unlink($this->filePath);