2 namespace TYPO3\CMS\Core\Locking;
17 use TYPO3\CMS\Core\Locking\Exception\LockAcquireException;
18 use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
19 use TYPO3\CMS\Core\Locking\Exception\LockCreateException;
55 $path = PATH_site . self::FILE_LOCK_FOLDER;
64 if (!is_writable($path)) {
67 $this->filePath = $path .
'flock_' . md5((
string)$subject);
87 public function acquire($mode = self::LOCK_CAPABILITY_EXCLUSIVE)
93 $this->filePointer = fopen($this->filePath,
'c');
94 if ($this->filePointer ===
false) {
99 $operation = $mode & self::LOCK_CAPABILITY_EXCLUSIVE ? LOCK_EX : LOCK_SH;
100 if ($mode & self::LOCK_CAPABILITY_NOBLOCK) {
101 $operation |= LOCK_NB;
105 $this->
isAcquired = flock($this->filePointer, $operation, $wouldBlock);
107 if ($mode & self::LOCK_CAPABILITY_NOBLOCK && !$this->
isAcquired && $wouldBlock) {
125 if (is_resource($this->filePointer)) {
126 if (flock($this->filePointer, LOCK_UN) ===
false) {
129 fclose($this->filePointer);
158 if (PHP_SAPI ===
'isapi') {
163 $capabilities = self::LOCK_CAPABILITY_EXCLUSIVE | self::LOCK_CAPABILITY_SHARED;
164 if (TYPO3_OS !==
'WIN'
165 || version_compare(PHP_VERSION,
'5.5.22',
'>') && version_compare(PHP_VERSION,
'5.6.0',
'<')
166 || version_compare(PHP_VERSION,
'5.6.6',
'>')
168 $capabilities |= self::LOCK_CAPABILITY_NOBLOCK;
171 return $capabilities;
181 @unlink($this->filePath);