Skip to content

Commit 5d6c52c

Browse files
committed
[Filesystem] Added documentation for the new LockHandler
1 parent 48bddaf commit 5d6c52c

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

components/filesystem/lockhandler.rst

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
1-
Lockhandler
1+
LockHandler
22
===========
3+
4+
.. versionadded:: 2.6
5+
The Lock handler feature was introduced in Symfony 2.6
6+
7+
What is a Lock?
8+
---------------
9+
10+
In computer science, a lock is a synchronization mechanism for enforcing
11+
limits on access to a resource in an environment where there are many
12+
threads of execution. A lock is designed to enforce a mutual exclusion
13+
concurrency control policy.
14+
15+
-- `Wikipedia`_
16+
17+
Usage
18+
-----
19+
20+
.. caution::
21+
22+
This lock handler works only when using one and only one host. If you have
23+
several hosts, you must not use this helper.
24+
25+
A lock can be used, for example, to allow only one instance of a command to run.
26+
27+
Usage::
28+
29+
use Symfony\Component\Filesystem\LockHandler;
30+
31+
$lockHandler = new LockHelper('hello.lock');
32+
if (!$lockHandler->lock()) {
33+
'The resource "hello" is already locked by another process.');
34+
35+
return 0;
36+
}
37+
38+
The first argument of the ``LockHelper`` is used to create a file on the local
39+
filesystem. By default, the LockHelper will create the file in the temporary
40+
directory. Another directory can be chosen by using the second argument.
41+
42+
The ``lock`` method tries to acquire the lock. If the lock is acquired, the
43+
method returns ``true``, false otherwise. If the method ``lock`` method is
44+
called severals times it will always return ``true`` if the lack was acquired on
45+
the first call.
46+
47+
The ``release`` method release the lock. So after the release, another process
48+
can lock the resource. The release is always released by PHP at the end of the
49+
script.
50+
51+
.. _Wikipedia: http://en.wikipedia.org/wiki/Lock_%28computer_science%29

0 commit comments

Comments
 (0)