Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/StreamWrapper/LocalStream.php \Drupal\Core\StreamWrapper\LocalStream::stream_lock()
  2. 9 core/lib/Drupal/Core/StreamWrapper/LocalStream.php \Drupal\Core\StreamWrapper\LocalStream::stream_lock()

Advisory file locking.

This method is called in response to flock(), when file_put_contents() (when flags contains LOCK_EX), stream_set_blocking() and when closing the stream (LOCK_UN).

Parameters

int $operation: One of:

  • LOCK_SH: To acquire a shared lock (reader).
  • LOCK_EX: To acquire an exclusive lock (writer).
  • LOCK_UN: To release a lock (shared or exclusive).
  • LOCK_NB: If you don't want flock() to block while locking. This operation is not supported on Windows.

Return value

bool Returns TRUE on success or FALSE on failure.

Overrides PhpStreamWrapperInterface::stream_lock

See also

flock()

stream_set_blocking()

http://php.net/manual/en/streamwrapper.stream-lock.php

1 method overrides LocalStream::stream_lock()
LocalReadOnlyStream::stream_lock in core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php
Support for flock().

File

core/lib/Drupal/Core/StreamWrapper/LocalStream.php, line 168

Class

LocalStream
Defines a Drupal stream wrapper base class for local files.

Namespace

Drupal\Core\StreamWrapper

Code

public function stream_lock($operation) {
  if (in_array($operation, [
    LOCK_SH,
    LOCK_EX,
    LOCK_UN,
    LOCK_NB,
  ])) {
    return flock($this->handle, $operation);
  }
  return TRUE;
}