Skip to content

Commit f19559d

Browse files
committed
[Filesystem] Added documentation for the new LockHandler
1 parent 604c21c commit f19559d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

components/filesystem/lockhandler.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,53 @@
11
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+
26+
A lock can be used, for example, to allow only one instance of a command to run.
27+
28+
29+
Usage::
30+
31+
use Symfony\Component\Filesystem\LockHandler;
32+
33+
$lockHandler = new LockHelper('hello.lock');
34+
if (!$lockHandler->lock()) {
35+
'The resource "hello" is already locked by another process.');
36+
37+
return 0;
38+
}
39+
40+
The first argument of the ``LockHelper`` is used to create a file on the local
41+
filesystem. By default, the LockHelper will create the file in the temporary
42+
directory. Another directory can be chosen by using the second argument.
43+
44+
The ``lock`` method tries to acquire the lock. If the lock is acquired, the
45+
method returns ``true``, false otherwise. If the method ``lock`` method is
46+
called severals times it will always return ``true`` if the lack was acquired on
47+
the first call.
48+
49+
The ``release`` method release the lock. So after the release, another process
50+
can lock the resource. The release is always released by PHP at the end of the
51+
script.
52+
53+
.. _Wikipedia: http://en.wikipedia.org/wiki/Lock_%28computer_science%29

0 commit comments

Comments
 (0)