public class Mutex

class.mutex.php #10

The Mutex class is a crude locking class that generates files with a specific time to live. It has basic functions to create a lock, release a lock or refresh a lock.

Methods

static void __shutdownCleanup()

Releases all locks on expired files.

public static
class.mutex.php #37
static boolean acquire(string $id, integer $ttl, string $path)

Creates a lock file if one does not already exist with a certain time to live (TTL) at a specific path. If a lock already exists, false will be returned otherwise boolean depending if a lock file was created successfully or not.

Parameters
  • $id stringThe name of the lock file, which gets obfuscated using generateLockFileName.

  • $ttl integerThe length, in seconds, that the lock should exist for. Defaults to 5.

  • $path stringThe path the lock should be written, defaults to the current working directory

static boolean lockExists(string $id, string $path)

Checks if a lock exists, purely on the presence on the lock file. This function takes the unobfuscated lock name Others should not depend on value returned by this function, because by the time it returns, the lock file can be created or deleted by another thread.

Parameters
  • $id stringThe name of the lock file, which gets obfuscated using generateLockFileName.

  • $path stringThe path the lock should be written, defaults to the current working directory

static boolean refresh(string $id, integer $ttl, string $path)

Updates a lock file to 'keep alive' for another 'x' seconds.

Parameters
  • $id stringThe name of the lock file, which gets obfuscated using __generateLockFileName().

  • $ttl integerThe length, in seconds, that the lock should be extended by. Defaults to 5.

  • $path stringThe path to the lock, defaults to the current working directory

public static
class.mutex.php #86
static boolean release(string $id, string $path)

Removes a lock file. This is the only way a lock file can be removed

Parameters
  • $id stringThe original name of the lock file (note that this will be different from the name of the file saved on the file system)

  • $path stringThe path to the lock, defaults to the current working directory

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details