You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+6-10Lines changed: 6 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,9 +44,9 @@ $lock->release();
44
44
45
45
use TH\Lock\FileLock;
46
46
47
-
$lock = new FileLock('/path/to/file');
47
+
$lock = new FileLock('/path/to/file', FileLock::SHARED);
48
48
49
-
$lock->acquire(FileLock::SHARED);
49
+
$lock->acquire();
50
50
51
51
// other processes that try to acquire an exclusive lock on the file will fail,
52
52
// processes that try to acquire an shared lock on the file will succeed
@@ -58,10 +58,6 @@ $lock->acquire();
58
58
// other processes can now acquire an exclusive lock on the file if no other shared lock remains.
59
59
```
60
60
61
-
### Upgrading or downgrading a lock
62
-
63
-
`$lock->acquire()` can be called multiple times to either upgrade a shared lock to an exclusive lock or downgrade an exclusive lock to a shared one. You can use it when you're done editing the file.
64
-
65
61
### Auto release
66
62
67
63
`$lock->release()` is called automatically when the lock is destroyed so you don't need to manually release it at the end of a script or if it got out of scope.
There are two methods you can use on a `FileLock`:
123
119
124
-
*`\TH\Lock\FileLock::acquire($exclusive = FileLock::EXCLUSIVE, $blocking = FileLock::NON_BLOCKING)` used to acquire a lock on the file
120
+
*`\TH\Lock\FileLock::acquire()` used to acquire a lock on the file
125
121
*`\TH\Lock\FileLock::release()` used to release a lock on the file
126
122
127
-
And one on a `FileFactory':
123
+
And one on a `FileFactory`:
128
124
129
-
*`\TH\Lock\FileFactory::create($resource, $owner = null)` used to create a `FileLock` for $resource
125
+
*`\TH\Lock\FileFactory::create($resource, $owner = null, $exclusive = FileLock::EXCLUSIVE, $blocking = FileLock::NON_BLOCKING)` used to create a `FileLock` for `$resource`
130
126
131
127
## Notes
132
128
133
-
Only lock file are currently supported. It means distributed processes can't be lock this way. It should be easy to implements the `TH\Lock\Lock`and `TH\Lock\LockFactory` interface to use a distributed lock mechanism (maybe with [Redis](http://redis.io/topics/distlock)).
129
+
Only lock file are currently supported. It means distributed processes can't be lock this way. It should be easy to implements the `TH\Lock\Lock` interface to use a distributed lock mechanism (maybe with [Redis](http://redis.io/topics/distlock)).
0 commit comments