# info > Apache::Session::Lock::File

---
type: CommandReference
command: Apache::Session::Lock::File
mode: perldoc
section: 
source: perldoc
---

## Quick Reference
- `my $locker = Apache::Session::Lock::File->new;` — create a lock object
- `$locker->acquire_write_lock($ref);` — acquire exclusive write lock
- `$locker->acquire_read_lock($ref);` — acquire shared read lock (no‑op if write locked)
- `$locker->release_all_locks($ref);` — release all read and write locks
- `$locker->clean('/var/lock/sessions', 3600);` — remove lock files older than 1 hour
- `tie %s, 'Apache::Session::Blah', $id, {LockDirectory => '/var/lock/sessions'}` — configure lock directory when using `Apache::Session`

## Name
`Apache::Session::Lock::File` - Provides mutual exclusion using flock

## Synopsis
perl
use Apache::Session::Lock::File;

my $locker = Apache::Session::Lock::File->new;

$locker->acquire_read_lock($ref);
$locker->acquire_write_lock($ref);
$locker->release_read_lock($ref);
$locker->release_write_lock($ref);
$locker->release_all_locks($ref);

$locker->clean($dir, $age);
## Configuration
- **LockDirectory** — directory path for lockfiles, passed via `tie` when used with `Apache::Session`. Defaults to `/tmp` if not supplied.

`new()` takes no arguments; the LockDirectory is picked up from the tie context.

## Examples
Direct locking with a file‑based locker:
perl
my $locker = Apache::Session::Lock::File->new;
$locker->acquire_write_lock($ref);
# critical section
$locker->release_write_lock($ref);
Cleaning old lock files:
perl
my $l = Apache::Session::Lock::File->new;
$l->clean('/var/lock/sessions', 3600);  # remove files unmodified for > 1 hour
## Notes
- **`clean($dir, $age)`** – unlinks lock files in `$dir` that have not been modified for `$age` seconds. Call this periodically to avoid directory congestion; the module deliberately never unlinks during normal operation to avoid breaking locks.
- **`acquire_read_lock` / `release_read_lock`** – do nothing if a write lock is already held; they merely set an internal flag. `release_read_lock` is not required by `Apache::Session` itself.
- **Win32 / Cygwin** – Windows cannot escalate locks, so all locks are exclusive. `release_read_lock` is unsupported. On Win32, files are deleted without being locked.

## See Also
[Apache::Session](http://localhost/phpMan.php/perldoc/Apache%3A%3ASession/markdown)