You are here

function _apdqc_lock_id in Asynchronous Prefetch Database Query Cache 7

Same name in this branch
  1. 7 apdqc.lock.apc.inc \_apdqc_lock_id()
  2. 7 apdqc.lock.db.inc \_apdqc_lock_id()
  3. 7 apdqc.lock.memcache_storage.inc \_apdqc_lock_id()
  4. 7 apdqc.lock.memcache.inc \_apdqc_lock_id()
  5. 7 apdqc.lock.redis.inc \_apdqc_lock_id()

Helper function to get this request's unique id.

Related topics

1 call to _apdqc_lock_id()
apdqc.lock.inc in ./apdqc.lock.inc
A database-mediated implementation of a locking mechanism.
1 string reference to '_apdqc_lock_id'
apdqc.lock.inc in ./apdqc.lock.inc
A database-mediated implementation of a locking mechanism.

File

./apdqc.lock.db.inc, line 77
A database-mediated implementation of a locking mechanism.

Code

function _apdqc_lock_id() {

  // Do not use drupal_static(). This identifier refers to the current
  // client request, and must not be changed under any circumstances
  // else the shutdown handler may fail to release our locks.
  static $lock_id;
  if (!isset($lock_id)) {

    // Assign a unique id.
    $lock_id = uniqid(mt_rand(), TRUE);

    // Compress the base16 string down to base85 string.
    $lock_id = str_replace('.', '', $lock_id);
    $lock_id = pack("H*", $lock_id);
    $lock_id = apdqc_lock_base85_encode($lock_id);

    // We only register a shutdown function if a lock is used.
    drupal_register_shutdown_function('lock_release_all', $lock_id);
  }
  return $lock_id;
}