PHPackages                             guanghua/queue - 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. guanghua/queue

ActiveYii-extension

guanghua/queue
==============

消息队列

19PHP

Since Mar 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/J-guanghua/queue)[ Packagist](https://packagist.org/packages/guanghua/queue)[ RSS](/packages/guanghua-queue/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Installation
------------

[](#installation)

安装此扩展的首选方法是通过 [composer](http://getcomposer.org/download/).

php composer.phar require --prefer-dist guanghua/queue "dev-master"

or add

“guanghua / queue”：“dev-master”到composer.json文件的require部分。

Usage
-----

[](#usage)

适用于 php

```
支持 文件 , redis , beanstalk 存储队列方式

use queue\file\Queue;
use queue\redis\Queue as RedisQueue;
use queue\beanstalk\Queue as BeanstalkQueue;

// 如果是手动载入，没有使用 composer
spl_autoload_register(function ($className) {
    // queue 目录所在路径
    $dirPath = __DIR__.'\\pieend';
    // 将命名空间中的反斜杠转换为目录分隔符
    $classFile =  str_replace('\\', '/', $dirPath. '\\'. $className) . '.php';
    // 如果文件存在，则包含文件
    if (is_file($classFile)) {
        include($classFile);
    }
});

// 定义一个文件下载类 并实现 queue\Job 接口方法
class DownloadJob extends \queue\base\Basics implements \queue\Job {

     public $url;
     public $file;

     public function execute($queue)
     {
         file_put_contents($this->file, file_get_contents($this->url));
     }

}

// 实例化一个本地文件队列
$queue = new Queue(["path"=>"./queue"]);

// 实例化一个redis队列
$queue = new RedisQueue([
   'hostname' => '127.0.0.1', //连接主机
   'port'     => 6379, //连接端口
   'database' => 0 //连接数据库
]);

// 实例化一个beanstalk队列
$queue = new BeanstalkQueue([
    'hostname' => '127.0.0.1', //连接主机
]);

// 文件队列
$queue->push(new DownloadJob(['url'=>'https://www.topgoer.cn/uploads/202008/cover_162950b2ef51313f_small.png','file'=>'./queue/image.jpg']));

// 将作业推送到5分钟后运行的队列中：
$queue->delay(5 * 60)->push(new DownloadJob(['url'=>' http://example.com/image.jpg','file'=>'./queue/image.jpg']));

// 任务执行的确切方式取决于所使用的驱动程序。驱动程序的大部分可以使用控制台命令运行。
$queue->run(); // 在循环中获取并执行任务的命令，直到队列为空：

// 生产作业方式
// 命令启动一个队列的守护程序：
$queue->listen();

// 该组件具有跟踪被推入队列的作业的状态的能力。

// 将作业推入队列并获取作业ID。
$ID = $queue->push（new DownloadJob) ;

// 工作正在等待执行。
$queue->isWaiting($ID);

// Worker从队列中获取作业，并执行它。
$queue->isReserved($ID);

// 这个工作是否被执行。
$queue->isDone($ID);
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f276791e5734a8cbcfde51477f2cc733f81c1fd95c55e150efa75bec3493f2b5?d=identicon)[J-guanghua](/maintainers/J-guanghua)

---

Top Contributors

[![J-guanghua](https://avatars.githubusercontent.com/u/28997235?v=4)](https://github.com/J-guanghua "J-guanghua (24 commits)")

### Embed Badge

![Health badge](/badges/guanghua-queue/health.svg)

```
[![Health](https://phpackages.com/badges/guanghua-queue/health.svg)](https://phpackages.com/packages/guanghua-queue)
```

PHPackages © 2026

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