kerekit/lockfile
最新稳定版本:2.0.1
Composer 安装命令:
composer require kerekit/lockfile
包简介
Lockfile mechanism with timeout option
README 文档
README
Install
composer install kerekit/lockfile
Example
<?php
use Kerekit\Lockfile\{Exception,Lock};
// Set a lockfile with 4 hours of timeout
$lock = new Lock (__DIR__ . '/lockfile.json', 4 * 60 * 60);
// Pass a callable to Lock::run()
try {
$lock->run (function () {
/**
* Do something here...
* - If it completes successfully, lockfile is closed, with last
* completion time updated.
* - If an exception is thrown, lockfile is closed, but last completion
* time remains the same.
* - If lockfile's last completion time is too old, fail with an
* exception.
*/
});
}
// Catch lockfile timeout
catch (Exception $e) {
if ($e->getCode () === Exception::CODE_TIMEOUT) {
echo "ERROR: Lockfile timeout reached!\n";
exit (1);
} else {
echo "ERROR: Failed to handle lockfile (" . $e->getMessage () . ")\n";
exit (1);
}
}
// Ignore any other errors
catch (\Throwable $e) {}
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2025-02-20