mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 18:11:52 +00:00
Filesystem: added some documentation for createLockFile() and releaseLockFile()
[ci skip]
This commit is contained in:
parent
37763685aa
commit
d456cb2419
@ -91,6 +91,16 @@ final class Filesystem{
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to get a lock on the specified file, creating it if it does not exist. This is typically used for IPC to
|
||||||
|
* inform other processes that some file or folder is already in use, to avoid data corruption.
|
||||||
|
* If this function succeeds in gaining a lock on the file, it writes the current PID to the file.
|
||||||
|
*
|
||||||
|
* @param string $lockFilePath
|
||||||
|
*
|
||||||
|
* @return int|null process ID of the process currently holding the lock failure, null on success.
|
||||||
|
* @throws \InvalidArgumentException if the lock file path is invalid (e.g. parent directory doesn't exist, permission denied)
|
||||||
|
*/
|
||||||
public static function createLockFile(string $lockFilePath) : ?int{
|
public static function createLockFile(string $lockFilePath) : ?int{
|
||||||
$resource = fopen($lockFilePath, "a+b");
|
$resource = fopen($lockFilePath, "a+b");
|
||||||
if($resource === false){
|
if($resource === false){
|
||||||
@ -114,6 +124,12 @@ final class Filesystem{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases a file lock previously acquired by createLockFile() and deletes the lock file.
|
||||||
|
*
|
||||||
|
* @param string $lockFilePath
|
||||||
|
* @throws \InvalidArgumentException if the lock file path is invalid (e.g. parent directory doesn't exist, permission denied)
|
||||||
|
*/
|
||||||
public static function releaseLockFile(string $lockFilePath) : void{
|
public static function releaseLockFile(string $lockFilePath) : void{
|
||||||
$lockFilePath = realpath($lockFilePath);
|
$lockFilePath = realpath($lockFilePath);
|
||||||
if($lockFilePath === false){
|
if($lockFilePath === false){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user