@@ -52,27 +52,27 @@ that represents the locked resource::
52
52
$lock->release();
53
53
}
54
54
55
- If the lock can not be acquired, the method returns ``false ``. You can safely
56
- call the `` acquire() `` method repeatedly, even if you already acquired it .
55
+ If the lock can not be acquired, the method returns ``false ``. The `` acquire() ``
56
+ method can be safely called repeatedly, even if the lock is already acquired.
57
57
58
58
.. note ::
59
59
60
60
Unlike other implementations, the Lock Component distinguishes locks
61
- instances even when they are created for the same resource. If you want to
62
- share a lock in several services, share the ``Lock `` instance returned by
63
- the ``Factory::createLock `` method.
61
+ instances even when they are created for the same resource. If a lock has
62
+ to be used by several services, they should share the same ``Lock `` instance
63
+ returned by the ``Factory::createLock `` method.
64
64
65
65
Blocking Locks
66
66
--------------
67
67
68
68
By default, when a lock cannot be acquired, the ``acquire `` method returns
69
- ``false `` immediately. In case you want to wait (indefinitely) until the lock
70
- can be created, pass ``false `` as the argument of the ``acquire() `` method. This
69
+ ``false `` immediately. To wait (indefinitely) until the lock
70
+ can be created, pass ``true `` as the argument of the ``acquire() `` method. This
71
71
is called a **blocking lock ** because the execution of your application stops
72
72
until the lock is acquired.
73
73
74
74
Some of the built-in ``Store `` classes support this feature. When they don't,
75
- you can decorate them with the ``RetryTillSaveStore `` class::
75
+ they can be decorated with the ``RetryTillSaveStore `` class::
76
76
77
77
use Symfony\Component\Lock\Factory;
78
78
use Symfony\Component\Lock\Store\RedisStore;
@@ -90,7 +90,7 @@ Expiring Locks
90
90
91
91
Locks created remotely are difficult to manage because there is no way for the
92
92
remote ``Store `` to know if the locker process is still alive. Due to bugs,
93
- fatal errors or segmentation faults, we can't guarantee that the ``release() ``
93
+ fatal errors or segmentation faults, it cannot be guaranteed that ``release() ``
94
94
method will be called, which would cause the resource to be locked infinitely.
95
95
96
96
The best solution in those cases is to create **expiring locks **, which are
@@ -100,12 +100,12 @@ the ``createLock()`` method. If needed, these locks can also be released early
100
100
with the ``release() `` method.
101
101
102
102
The trickiest part when working with expiring locks is choosing the right TTL.
103
- If it's too short, other processes could acquire the lock before finishing your
104
- work ; it it's too long and the process crashes before calling the ``release() ``
103
+ If it's too short, other processes could acquire the lock before finishing the
104
+ job ; it it's too long and the process crashes before calling the ``release() ``
105
105
method, the resource will stay locked until the timeout::
106
106
107
107
// ...
108
- // create a expiring lock that lasts 30 seconds
108
+ // create an expiring lock that lasts 30 seconds
109
109
$lock = $factory->createLock('charts-generation', 30);
110
110
111
111
$lock->acquire();
@@ -173,16 +173,16 @@ PHP process is terminated::
173
173
.. caution ::
174
174
175
175
Beware that some file systems (such as some types of NFS) do not support
176
- locking. In those cases, it's better to use a local file or a remote store
177
- based on Redis or Memcached.
176
+ locking. In those cases, it's better to use a directory on a local disk
177
+ drive or a remote store based on Redis or Memcached.
178
178
179
179
.. _lock-store-memcached :
180
180
181
181
MemcachedStore
182
182
~~~~~~~~~~~~~~
183
183
184
- The MemcachedStore saves locks on a Memcached server, so first you must create
185
- a Memcached connection implements the ``\Memcached `` class. This store does not
184
+ The MemcachedStore saves locks on a Memcached server, it requires a Memcached
185
+ connection implementing the ``\Memcached `` class. This store does not
186
186
support blocking, and expects a TTL to avoid stalled locks::
187
187
188
188
use Symfony\Component\Lock\Store\MemcachedStore;
@@ -201,8 +201,8 @@ support blocking, and expects a TTL to avoid stalled locks::
201
201
RedisStore
202
202
~~~~~~~~~~
203
203
204
- The RedisStore saves locks on a Redis server, so first you must create a Redis
205
- connection implements the ``\Redis ``, ``\RedisArray ``, ``\RedisCluster `` or
204
+ The RedisStore saves locks on a Redis server, it requires a Redis connection
205
+ implementing the ``\Redis ``, ``\RedisArray ``, ``\RedisCluster `` or
206
206
``\Predis `` classes. This store does not support blocking, and expects a TTL to
207
207
avoid stalled locks::
208
208
@@ -233,7 +233,7 @@ The CombinedStore is designed for High Availability applications because it
233
233
manages several stores in sync (for example, several Redis servers). When a lock
234
234
is being acquired, it forwards the call to all the managed stores, and it
235
235
collects their responses. If a simple majority of stores have acquired the lock,
236
- then the lock is considered as acquired; otherwise is not acquired::
236
+ then the lock is considered as acquired; otherwise as not acquired::
237
237
238
238
use Symfony\Component\Lock\Quorum\ConsensusStrategy;
239
239
use Symfony\Component\Lock\Store\CombinedStore;
@@ -249,8 +249,9 @@ then the lock is considered as acquired; otherwise is not acquired::
249
249
250
250
$store = new CombinedStore($stores, new ConsensusStrategy());
251
251
252
- Instead of the simple majority strategy (``ConsensusStrategy ``) you can use the
253
- ``UnanimousStrategy `` to require the lock to be acquired in all the stores.
252
+ Instead of the simple majority strategy (``ConsensusStrategy ``) an
253
+ ``UnanimousStrategy `` can be used to require the lock to be acquired in all
254
+ he stores.
254
255
255
256
.. _`locks` : https://en.wikipedia.org/wiki/Lock_(computer_science)
256
257
.. _Packagist : https://packagist.org/packages/symfony/lock
0 commit comments