PHPackages                             alanalbert/php-async - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. alanalbert/php-async

Abandoned → [alanalbert/php-async](/?search=alanalbert%2Fphp-async)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

alanalbert/php-async
====================

PHP实现异步回调

v0.1.6(6y ago)213MITPHPPHP &gt;=5.6

Since Aug 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/anhoder/php-async)[ Packagist](https://packagist.org/packages/alanalbert/php-async)[ RSS](/packages/alanalbert-php-async/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

php-async
=========

[](#php-async)

PHP异步回调的简单实现

**php-fpm模式的使用，仍在测试，可能会出现未知问题。**

- php-fpm模式下已解决的问题：

> 解决异步进程执行完成后，成为僵尸进程的问题
>
> 经测试，异步进程的fork不受php-fpm配置的进程数限制

Requirement / 依赖
----------------

[](#requirement--依赖)

- ext-pcntl
- php &gt; 5.6

Installation / 安装
-----------------

[](#installation--安装)

```
composer require alanalbert/php-async
```

Usage / 使用
----------

[](#usage--使用)

> 该库可以工作在php-fpm或cli模式下。（但是，每个异步任务会创建一个进程进行处理，直至任务完成后才会被**彻底杀死**）

**现在可以使用[PHP Async Manager](https://github.com/AlanAlbert/php-async-manager)命令行工具进行异步任务管理。**

### 使用实例

[](#使用实例)

```
require './vendor/autoload.php';

use Async\DaemonProcess;
use Async\Job;

// 异步操作任务
$job = new Job();
// 设置异步任务
$job->setJob(function () {
  sleep(5);
});
// 设置回调函数
$job->setCallback(function () {
  file_put_contents('处理完成.txt', '处理完成');
});

// 实例化异步进程
$daemon = new DaemonProcess($job);
$daemon->run();
```

### Async\\DaemonProcess

[](#asyncdaemonprocess)

守护进程类，该类提供的方法有：

```
// 构造函数，接收实现Async\Contract\JobInterface接口的类的实例
__construct(Async\Contract\JobInterface $job): void

// 运行守护进程
run(): void
```

### Async\\Contract\\JobInterface

[](#asynccontractjobinterface)

异步任务接口，该接口很简单，只需要实现两个方法即可：

```
// 异步任务
job(): void
// 回调任务
callback(): void
```

### Async\\Job

[](#asyncjob)

该类实现了`Async\Contract\JobInterface`接口，使用起来更方便，其提供的方法有：

```
// 设置异步任务
// $job可以为callable或Closure类型
// $params为异步任务需要使用的参数，会在执行时，传入给异步任务
setJob($job, $params = null): void

// 设置回调函数
// $callback可以为callable或Closure类型
// $params为回调函数需要使用的参数，会在执行时，传入给回调函数
setCallback($callback, $params = null): void
```

### 其他

[](#其他)

- 在使用该库执行异步任务时，会生成日志文件，位于`/tmp/php-async-log/`下
- 如果不使用`Async\Job`类，也可以自定义类并实现`Async\Contract\JobInterface`接口

TODO
----

[](#todo)

- ...

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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 ~1 days

Total

7

Last Release

2468d ago

PHP version history (2 changes)v0.1.0PHP &gt;5.6

v0.1.3PHP &gt;=5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/27605589?v=4)[anhoder](/maintainers/anhoder)[@anhoder](https://github.com/anhoder)

---

Top Contributors

[![anhoder](https://avatars.githubusercontent.com/u/27605589?v=4)](https://github.com/anhoder "anhoder (22 commits)")

---

Tags

asyncphpphp-asyncphp-fpm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alanalbert-php-async/health.svg)

```
[![Health](https://phpackages.com/badges/alanalbert-php-async/health.svg)](https://phpackages.com/packages/alanalbert-php-async)
```

PHPackages © 2026

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