99 $this->loops = (int)
$loops;
102 $this->step = (int)
$step;
104 if (
$method ===
'' && isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'lockingMode'])) {
109 case self::LOCKING_METHOD_SIMPLE:
111 case self::LOCKING_METHOD_FLOCK:
112 $this->
id = md5(
$id);
115 case self::LOCKING_METHOD_SEMAPHORE:
116 $this->
id = abs(crc32(
$id));
118 case self::LOCKING_METHOD_DISABLED:
121 throw new \InvalidArgumentException(
'No such locking method "' .
$method .
'"', 1294586097);
132 switch ($this->method) {
133 case self::LOCKING_METHOD_FLOCK:
138 @unlink($this->resource);
141 case self::LOCKING_METHOD_SEMAPHORE:
142 @sem_remove($this->resource);
156 $this->resource = sem_get($this->
id, 1);
157 if ($this->resource === FALSE) {
158 throw new \RuntimeException(
'Unable to get semaphore with id ' . $this->
id, 1313828196);
180 switch ($this->method) {
181 case self::LOCKING_METHOD_SIMPLE:
182 if (file_exists($this->resource)) {
183 $this->
sysLog(
'Waiting for a different process to release the lock');
184 $maxExecutionTime = (int)ini_get(
'max_execution_time');
185 $maxAge = time() - ($maxExecutionTime ?: 120);
186 if (@filectime($this->resource) < $maxAge) {
187 @unlink($this->resource);
196 $this->
sysLog(
'Lock acquired');
201 usleep($this->step * 1000);
204 throw new \RuntimeException(
'Lock file could not be created', 1294586098);
207 case self::LOCKING_METHOD_FLOCK:
208 $this->filePointer = fopen($this->resource,
'c');
209 if ($this->filePointer === FALSE) {
210 throw new \RuntimeException(
'Lock file could not be opened', 1294586099);
213 if (flock($this->filePointer, LOCK_EX | LOCK_NB)) {
215 } elseif (flock($this->filePointer, LOCK_EX)) {
219 throw new \RuntimeException(
'Could not lock file "' . $this->resource .
'"', 1294586100);
223 case self::LOCKING_METHOD_SEMAPHORE:
226 if (@sem_acquire($this->resource)) {
234 case self::LOCKING_METHOD_DISABLED:
250 if ($this->isAcquired) {
253 $this->isAcquired = FALSE;
254 switch ($this->method) {
255 case self::LOCKING_METHOD_SIMPLE:
256 if (file_exists($this->resource)) {
257 $this->
sysLog(
'Waiting for a different process to release the lock');
258 $maxExecutionTime = (int)ini_get(
'max_execution_time');
259 $maxAge = time() - ($maxExecutionTime ?: 120);
260 if (@filectime($this->resource) < $maxAge) {
261 @unlink($this->resource);
270 $this->
sysLog(
'Lock acquired');
271 $this->isAcquired = TRUE;
274 usleep($this->step * 1000);
277 case self::LOCKING_METHOD_FLOCK:
278 $this->filePointer = fopen($this->resource,
'c');
279 if ($this->filePointer === FALSE) {
280 throw new \RuntimeException(
'Lock file could not be opened', 1294586099);
282 if (flock($this->filePointer, LOCK_EX)) {
283 $this->isAcquired = TRUE;
286 case self::LOCKING_METHOD_SEMAPHORE:
288 if (@sem_acquire($this->resource)) {
289 $this->isAcquired = TRUE;
292 case self::LOCKING_METHOD_DISABLED:
309 if ($this->isAcquired) {
312 if ($this->method === self::LOCKING_METHOD_FLOCK) {
313 $this->filePointer = fopen($this->resource,
'c');
314 if ($this->filePointer === FALSE) {
315 throw new \RuntimeException(
'Lock file could not be opened', 1294586099);
317 if (flock($this->filePointer, LOCK_SH)) {
318 $this->isAcquired = TRUE;
330 if (!$this->isAcquired) {
334 switch ($this->method) {
335 case self::LOCKING_METHOD_SIMPLE:
340 if (@unlink($this->resource) === FALSE) {
345 case self::LOCKING_METHOD_FLOCK:
346 if (is_resource($this->filePointer)) {
347 if (flock($this->filePointer, LOCK_UN) === FALSE) {
350 fclose($this->filePointer);
353 case self::LOCKING_METHOD_SEMAPHORE:
354 if (!@sem_release($this->resource)) {
358 case self::LOCKING_METHOD_DISABLED:
363 $this->isAcquired = FALSE;
411 switch ($this->method) {
412 case self::LOCKING_METHOD_SIMPLE:
413 if (file_exists($this->resource)) {
414 $maxExecutionTime = (int)ini_get(
'max_execution_time');
415 $maxAge = time() - ($maxExecutionTime ?: 120);
416 if (@filectime($this->resource) < $maxAge) {
417 @unlink($this->resource);
424 case self::LOCKING_METHOD_FLOCK:
427 case self::LOCKING_METHOD_SEMAPHORE:
430 case self::LOCKING_METHOD_DISABLED:
464 public function sysLog($message, $severity = 0) {
465 if ($this->isLoggingEnabled) {
466 GeneralUtility::sysLog(
'Locking [' . $this->method .
'::' . $this->
id .
']: ' . trim($message), $this->syslogFacility, $severity);
479 $path = PATH_site . self::FILE_LOCK_FOLDER;
480 if (!is_dir($path)) {
485 throw new \RuntimeException(
'Cannot create directory ' . $path, 1395140007);
488 if (!is_writable($path)) {
489 throw new \RuntimeException(
'Cannot write to directory ' . $path, 1396278700);
static isAllowedAbsPath($path)
const LOCKING_METHOD_SEMAPHORE
static isFirstPartOfStr($str, $partStr)
sysLog($message, $severity=0)
static fixPermissions($path, $recursive=FALSE)
const LOCKING_METHOD_SIMPLE
setEnableLogging($isLoggingEnabled)
__construct($id, $method=self::LOCKING_METHOD_SIMPLE, $loops=0, $step=0)
const SYSLOG_SEVERITY_WARNING
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
const LOCKING_METHOD_FLOCK
const LOCKING_METHOD_DISABLED
setSyslogFacility($syslogFacility)