File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 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:
207207``getRemainingLifetime() `` (which returns ``null `` or a ``float ``
208208as 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+
210242Shared Locks
211243------------
212244
Original file line number Diff line number Diff line change @@ -1039,7 +1039,7 @@ The ``YamlEncoder`` Context Options
10391039The ``encode() `` method, like other encoder, uses ``context `` to set
10401040configuration options for the YamlEncoder an associative array::
10411041
1042- $xmlEncoder ->encode($array, 'xml ', $context);
1042+ $yamlEncoder ->encode($array, 'yaml ', $context);
10431043
10441044These are the options available:
10451045
You can’t perform that action at this time.
0 commit comments