PHPackages                             ywna/swbt - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. ywna/swbt

ActiveLibrary[Queues &amp; Workers](/categories/queues)

ywna/swbt
=========

A PHP Framework of swoole with beanstalkd

v0.1.3(7y ago)2033541Apache-2.0PHPPHP ^7.0CI failing

Since Jun 5Pushed 5y ago2 watchersCompare

[ Source](https://github.com/YWNA/SWBT)[ Packagist](https://packagist.org/packages/ywna/swbt)[ Docs](https://github.com/YWNA/SWBT)[ RSS](/packages/ywna-swbt/feed)WikiDiscussions master Synced today

READMEChangelog (5)Dependencies (7)Versions (25)Used By (1)

SWBT
====

[](#swbt)

[![SWBT](logo.jpg)](logo.jpg)

[![Github Releases](https://camo.githubusercontent.com/008f29815d2752760196f87e3a1433e09d66500250d034a64e1403fa6aa661e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f79776e612f737762742f6c61746573742f746f74616c2e737667)](https://github.com/YWNA/SWBT)[![Packagist](https://camo.githubusercontent.com/d480b7382375fda122f92314be2044366531b219ba4e7ff28d8999ffe1d5ba41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79776e612f737762742e737667)](https://packagist.org/packages/ywna/swbt)[![GitHub commits](https://camo.githubusercontent.com/3caea427c00e57c9f949d82eaf68432a1e476b0d458e6b22e2f7edc87b05f243/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f79776e612f737762742f6c61746573742e737667)](https://camo.githubusercontent.com/3caea427c00e57c9f949d82eaf68432a1e476b0d458e6b22e2f7edc87b05f243/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f79776e612f737762742f6c61746573742e737667)[![GitHub release](https://camo.githubusercontent.com/f6503c2e3c34c85f84400712824e2a0c8bda0d972cf6ca9c059283254dbdf2ed/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f79776e612f737762742e737667)](https://github.com/YWNA/SWBT/releases)

A PHP Framework of [swoole](https://www.swoole.com/) with [beanstalkd](http://kr.github.io/beanstalkd/)

### Install [beanstalkd](https://github.com/kr/beanstalkd)

[](#install-beanstalkd)

- Beanstalk is a simple, fast work queue.
- [Doc](https://github.com/kr/beanstalkd/blob/master/doc/protocol.zh-CN.md)
- Ubuntu,Install Command ```
    sudo apt-get install beanstalkd

    ```

    [更多方式](http://kr.github.io/beanstalkd/download.html)
- 框架实现的流程图 [![SWBT](flowchart.png)](flowchart.png)

### Install [Swoole](http://www.swoole.com)

[](#install-swoole)

- sudo apt-get install -y php-pear php7.0-dev
- sudo pecl install swoole
- Swoole仅支持 Linux、FreeBSD、MacOS 三种操作系统（在Windows平台，可使用CygWin或WSL(Windows Subsystem for Linux)），因此**基于Swoole的SWBT同样无法在Windows系统下运行**。
- [Doc](https://wiki.swoole.com/wiki/page/6.html)

### Install SWBT

[](#install-swbt)

- Composer安装 ```
    composer config bin-dir bin
    composer require ywna/swbt

    ```

### Start-Up（作为第三方依赖）

[](#start-up作为第三方依赖)

- 消息队列的状态 ```
    vendor/bin/SWBT status
    ```

    ```
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"hostname":"chenbo-Vostro-3559","id":"c53887df34bcd127","job-timeouts":"0","pid":"1113","total-connections":"3","total-jobs":"0","uptime":"31447","version":"1.9"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-jobs-urgent":"15","des":"优先级小于1024状态为ready的job数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-jobs-ready":"39","des":"状态为ready的job数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-jobs-reserved":"0","des":"状态为reserved的job数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-jobs-delayed":"0","des":"状态为delayed的job数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-jobs-buried":"2","des":"状态为buried的job数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-put":"0","des":"总共执行put指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-peek":"0","des":"总共执行peek指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-peek-ready":"0","des":"总共执行peek-ready指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-peek-delayed":"0","des":"总共执行peek-delayed指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-peek-buried":"0","des":"总共执行peek-buried指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-reserve":"0","des":"总共执行reserve指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-reserve-with-timeout":"0","des":"总共执行reserve-with-timeout指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-delete":"0","des":"总共执行delete指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-release":"0","des":"总共执行release指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-use":"0","des":"总共执行use指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-watch":"0","des":"总共执行watch指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-ignore":"0","des":"总共执行ignore指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-bury":"0","des":"总共执行bury指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-kick":"0","des":"总共执行kick指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-touch":"0","des":"总共执行touch指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-stats":"3","des":"总共执行stats指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-stats-job":"0","des":"总共执行stats-job指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-stats-tube":"0","des":"总共执行stats-tube指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-list-tubes":"0","des":"总共执行list-tubes指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-list-tube-used":"0","des":"总共执行list-tube-used指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-list-tubes-watched":"0","des":"总共执行list-tubes-watched指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"cmd-pause-tube":"0","des":"总共执行pause-tube指令的次数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"max-job-size":"5242880","des":"job的数据部分最大长度"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-tubes":"5","des":"当前存在的tube数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-connections":"1","des":"当前打开的连接数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-producers":"0","des":"当前所有的打开的连接中至少执行一次put指令的连接数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-workers":"0","des":"当前所有的打开的连接中至少执行一次reserve指令的连接数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"current-waiting":"0","des":"当前所有的打开的连接中执行reserve指令但是未响应的连接数量"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"rusage-utime":"0.000000","des":"进程总共占用的用户CPU时间"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"rusage-stime":"0.003083","des":"进程总共占用的系统CPU时间"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"binlog-oldest-index":"118","des":"开始储存jobs的binlog索引号"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"binlog-current-index":"123","des":"当前储存jobs的binlog索引号"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"binlog-records-migrated":"0","des":"is the cumulative number of records written as part of compaction."} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"binlog-records-written":"0","des":"binlog累积写入的记录数"} []
    [2018-06-25 17:46:04] SWBT.INFO: Status Info: {"binlog-max-size":"10485760","des":"binlog的最大容量"} []

    ```
- 消息队列的Job状态信息 ```
    vendor/bin/SWBT status-job
    ```

    ```
    [2018-06-25 17:39:20] SWBT.INFO: Status Info: {"hostname":"chenbo-Vostro-3559","id":"c53887df34bcd127","job-timeouts":"0","pid":"1113","total-connections":"2","total-jobs":"0","uptime":"31043","version":"1.9"} []
    [2018-06-25 17:39:20] SWBT.INFO: Status Info: {"current-jobs-urgent":"15","des":"优先级小于1024状态为ready的job数量"} []
    [2018-06-25 17:39:20] SWBT.INFO: Status Info: {"current-jobs-ready":"39","des":"状态为ready的job数量"} []
    [2018-06-25 17:39:20] SWBT.INFO: Status Info: {"current-jobs-reserved":"0","des":"状态为reserved的job数量"} []
    [2018-06-25 17:39:20] SWBT.INFO: Status Info: {"current-jobs-delayed":"0","des":"状态为delayed的job数量"} []
    [2018-06-25 17:39:20] SWBT.INFO: Status Info: {"current-jobs-buried":"2","des":"状态为buried的job数量"} []

    ```
- bash端方式 ```
    vendor/bin/SWBT run

    ```
- 守护进程deamon方式 ```
    vendor/bin/SWBT start

    ```
- 停止 ```
    vendor/bin/SWBT stop

    ```
- 队列管道配置 ```
    swb/config/SWBT.php

    return [
        'tubes' => [
            //队列处理管道名称
            'test' => [
                'worker_num' => 3, //处理进程数量
                'class' => \SWBT\Worker\TestWorker::class //队列处理类
            ]
        ]
    ];

    ```
- 队列处理类模板，继承BaseWorker类和Worker接口 ```
