PHPackages                             sn01615/file-lock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sn01615/file-lock

ActiveLibrary

sn01615/file-lock
=================

Php file lock tool.

v1.1.5(3mo ago)185MITPHP

Since May 2Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/sn01615/FileLock)[ Packagist](https://packagist.org/packages/sn01615/file-lock)[ RSS](/packages/sn01615-file-lock/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (7)DependenciesVersions (8)Used By (0)

### 应用场景

[](#应用场景)

1. 限制只开启一个或有限个进程运行
2. 单机单线程随机抢占锁

### 局限性

[](#局限性)

只能在同一台服务器内生效 需要临时目录写入权限 (会在临时目录创建一个 \_PHP\_FileLock\_xxx 类似的文件)

### Install

[](#install)

```
composer require sn01615/file-lock

```

### Usage

[](#usage)

```
use PhpUtils\FileLock;

# Get lock
$status = FileLock::getLock('lockKey');
if ($status) {
    # Get lock success
} else {
    # It's locked.
}

# Unlock
FileLock::unlock('lockKey');
```

有作用域的sleep排队的锁

```
// $locker 释放的时候锁就会释放
$locker = new \PhpUtils\FileLocker();
$locker->wait("aaa");
```

单机单线程随机抢占锁：

```
// 一直排队直到随机抢占到锁
\PhpUtils\Locker::wait("aaa");

// 等待10秒, 如果10秒内没有抢占到锁则返回false, 否则返回true
if (\PhpUtils\Locker::wait("aaa", 10)) {
    echo "获取锁成功";
} else {
    echo "获取锁失败";
}
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance82

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~412 days

Recently: every ~247 days

Total

7

Last Release

94d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fd6cb8950d77fdebcef7c1cd1eac849e5610deddf19aa539f76b371ccaee152?d=identicon)[sn01615](/maintainers/sn01615)

---

Top Contributors

[![sn01615](https://avatars.githubusercontent.com/u/7794149?v=4)](https://github.com/sn01615 "sn01615 (11 commits)")

---

Tags

file-lockfilelockphpfilelock

### Embed Badge

![Health badge](/badges/sn01615-file-lock/health.svg)

```
[![Health](https://phpackages.com/badges/sn01615-file-lock/health.svg)](https://phpackages.com/packages/sn01615-file-lock)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
