Skip to content

Commit e1714db

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: Tweaks [Lock] Added paragraph about auto release Fixed typo for YamlEncoder section
2 parents 02d3d1a + 4ed8ef0 commit e1714db

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

components/lock.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,38 @@ This component also provides two useful methods related to expiring locks:
207207
``getRemainingLifetime()`` (which returns ``null`` or a ``float``
208208
as seconds) and ``isExpired()`` (which returns a boolean).
209209

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+
210242
Shared Locks
211243
------------
212244

components/serializer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ The ``YamlEncoder`` Context Options
10391039
The ``encode()`` method, like other encoder, uses ``context`` to set
10401040
configuration options for the YamlEncoder an associative array::
10411041

1042-
$xmlEncoder->encode($array, 'xml', $context);
1042+
$yamlEncoder->encode($array, 'yaml', $context);
10431043

10441044
These are the options available:
10451045

0 commit comments

Comments
 (0)