-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reworded the explanation about when a lock is released #4903
Changes from 1 commit
82a9635
89a7320
e632d49
6e14bac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,8 +62,23 @@ You can pass an optional blocking argument as the first argument to the | |
``lock()`` method, which defaults to ``false``. If this is set to ``true``, your | ||
PHP code will wait indefinitely until the lock is released by another process. | ||
|
||
The resource is automatically released by PHP at the end of the script. In | ||
addition, you can invoke the | ||
:method:`Symfony\\Component\\Filesystem\\LockHandler::release` method to release | ||
the lock explicitly. Once it's released, any other process can lock the | ||
resource. | ||
Beware that the resource lock is automatically released as soon as PHP applies the | ||
garbage-collection process to the ``LockHandler`` object. This means that if you | ||
refactor the first example showed in this article as follows: | ||
|
||
.. code-block:: php | ||
|
||
use Symfony\Component\Filesystem\LockHandler; | ||
|
||
if (!(new LockHandler('hello.lock'))->lock()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is one space too much in the indent of this line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, I don't like this new syntax. It's too much stuff in one line and works only in >=PHP 5.4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wouterj it I'm right, this PHP 5.4 example is precisely needed to make the code fail as explained above. |
||
// the resource "hello" is already locked by another process | ||
|
||
return 0; | ||
} | ||
|
||
Now the code won't work as expected, because PHP's garbage collection mechanism | ||
removes the reference to the ``LockHandler`` object and thus, the lock is released | ||
just after it's been created. | ||
|
||
Another alternative way to release the lock explicitly when needed is to use the | ||
:method:`Symfony\\Component\\Filesystem\\LockHandler::release` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the shorthand
::
syntax