PHP Function Reference

PHP streamWrapper stream_lock() Method



The PHP streamWrapper::stream_lock() method is used to lock or release a file. 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).

Syntax

public streamWrapper::stream_lock(operation)

Parameters

operation Required. operation can be one of the following:
  • LOCK_SH - A shared lock (reader). Allow other processes to access the file.
  • LOCK_EX - An exclusive lock (writer). Prevent other processes from accessing the file.
  • LOCK_UN - Release a lock (shared or exclusive).
  • LOCK_NB - If you don't want flock() to block while locking (not supported on Windows).

Return Value

Returns true on success or false on failure.

Exceptions

Emits E_WARNING if call to this method fails (i.e. not implemented).


❮ PHP Streams Reference