@@ -62,23 +62,25 @@ You can pass an optional blocking argument as the first argument to the
62
62
``lock() `` method, which defaults to ``false ``. If this is set to ``true ``, your
63
63
PHP code will wait indefinitely until the lock is released by another process.
64
64
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 ::
68
66
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:
70
70
71
- use Symfony\Component\Filesystem\LockHandler;
71
+ .. code-block :: php
72
72
73
- if (!(new LockHandler('hello.lock'))->lock()) {
74
- // the resource "hello" is already locked by another process
73
+ use Symfony\Component\Filesystem\LockHandler;
75
74
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
+ }
78
80
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.
82
84
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