File tree 2 files changed +33
-1
lines changed
Filter options
2 files changed +33
-1
lines changed
Original file line number Diff line number Diff line change @@ -207,6 +207,38 @@ This component also provides two useful methods related to expiring locks:
207
207
``getRemainingLifetime() `` (which returns ``null `` or a ``float ``
208
208
as seconds) and ``isExpired() `` (which returns a boolean).
209
209
210
+ Automatically Releasing The Lock
211
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212
+
213
+ Lock are automatically released when their Lock objects are destructed. This is
214
+ an implementation detail that will be important when sharing Locks between
215
+ processes. In the example below, ``pcntl_fork() `` creates two processes and the
216
+ Lock will be released automatically as soon as one process finishes::
217
+
218
+ // ...
219
+ $lock = $factory->createLock('report-generation', 3600);
220
+ if (!$lock->acquire()) {
221
+ return;
222
+ }
223
+
224
+ $pid = pcntl_fork();
225
+ if (-1 === $pid) {
226
+ // Could not fork
227
+ exit(1);
228
+ } elseif ($pid) {
229
+ // Parent process
230
+ sleep(30);
231
+ } else {
232
+ // Child process
233
+ echo 'The lock will be released now.'
234
+ exit(0);
235
+ }
236
+ // ...
237
+
238
+ To disable this behavior, set to ``false `` the third argument of
239
+ ``LockFactory::createLock() ``. That will make the lock acquired for 3600 seconds
240
+ or until ``Lock::release() `` is called.
241
+
210
242
Shared Locks
211
243
------------
212
244
Original file line number Diff line number Diff line change @@ -1043,7 +1043,7 @@ The ``YamlEncoder`` Context Options
1043
1043
The ``encode() `` method, like other encoder, uses ``context `` to set
1044
1044
configuration options for the YamlEncoder an associative array::
1045
1045
1046
- $xmlEncoder ->encode($array, 'xml ', $context);
1046
+ $yamlEncoder ->encode($array, 'yaml ', $context);
1047
1047
1048
1048
These are the options available:
1049
1049
You can’t perform that action at this time.
0 commit comments