@@ -62,23 +62,25 @@ You can pass an optional blocking argument as the first argument to the
6262``lock() `` method, which defaults to ``false ``. If this is set to ``true ``, your
6363PHP code will wait indefinitely until the lock is released by another process.
6464
65- Beware that the resource lock is automatically released as soon as PHP applies the
66- garbage-collection process to the ``LockHandler `` object. This means that if you
67- refactor the first example showed in this article as follows:
65+ .. caution ::
6866
69- .. code-block :: php
67+ Beware that the resource lock is automatically released as soon as PHP applies
68+ the garbage-collection process to the ``LockHandler `` object. This means that
69+ if you refactor the first example showed in this article as follows:
7070
71- use Symfony\Component\Filesystem\LockHandler;
71+ .. code-block :: php
7272
73- if (!(new LockHandler('hello.lock'))->lock()) {
74- // the resource "hello" is already locked by another process
73+ use Symfony\Component\Filesystem\LockHandler;
7574
76- return 0;
77- }
75+ if (!(new LockHandler('hello.lock'))->lock()) {
76+ // the resource "hello" is already locked by another process
77+
78+ return 0;
79+ }
7880
79- Now the code won't work as expected, because PHP's garbage collection mechanism
80- removes the reference to the ``LockHandler `` object and thus, the lock is released
81- just after it's been created.
81+ Now the code won't work as expected, because PHP's garbage collection mechanism
82+ removes the reference to the ``LockHandler `` object and thus, the lock is released
83+ just after it's been created.
8284
83- Another alternative way to release the lock explicitly when needed is to use the
84- :method: `Symfony\\ Component\\ Filesystem\\ LockHandler::release ` method.
85+ Another alternative way to release the lock explicitly when needed is to use the
86+ :method: `Symfony\\ Component\\ Filesystem\\ LockHandler::release ` method.
0 commit comments