vinelab/minion 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vinelab/minion

最新稳定版本:v1.4.0

Composer 安装命令:

composer require vinelab/minion

包简介

A Simple WAMP (Web Application Messaging Protocol) server and command line tool

README 文档

README

Build Status

SensioLabsInsight

Minion

A simplified client the WAMP v2 protocol (Web Application Messaging Protocol) with a handy command line tool - PHP WebSocket made easy.

Based on the great work put together by Thruway, Minion will give you the simplicity and flexibility of running minion run and get a client running in no time. In addition to helping you structure your application. See How It Works for details.

For a jump-start head over to the Quick Start Guide or read on for detailed docs. Or you may take a look at the Examples to get an idea about how this works.

Installation

Composer

Add the following to require in composer.json

"vinelab/minion": "*"

Then run composer update to install.

Laravel Bounties

  • Add Vinelab\Minion\MinionServiceProvider to the providers array in your app.php and you'll have a Minion facade available throught your project.
  • The command line tool is available through artisan as php artisan minion:run see CLI
  • Run php artisan vendor:publish and head to app/config/minion.php to configure your minion.

Configuration

Configure the connection parameters you want your client to use when it connects to a WAMP router.

Router

$m = new Minion():
$m->run(['realm' => 'myrealm', 'host' => 'some.host.ws', 'port' => 8182]);

Provider Registration

$m = new Minion();
$m->register('ChatProvider');
$m->register('MyApp\Providers\NotificationProvider'):
$m->run();

You may also find it useful to list the providers in the config as such:

$m = new Minion();
$m->run(
    [
        'port'     => 9876,

        'host'     => 'the.host',

        'realm'    => 'somerealm',

        'register' => [
            'ChatProvider',
            'SomeOtherProvider'
            'NotificationProvider',
        ]
    ]
);

In existing applications it may be useful to be re-use an existing ReactPHP loop. You can pass in a LoopInterface like so:

$loop = React\EventLoop\Factory::create();
$m = new Minion();
$m->run([], $loop);

Usage

The idea behind Minion is to help structure your application and get it ready for scale with real-time communication by using providers to register RPCs and publish and subscribe to topics with predefined functionalities to make things quick. For more about RPCs and Pub/Sub see Introduction to WAMP programming

How It Works

WAMP is a protocol that defines a Router that handles connections of clients, your application is one of these clients and the application logic is implemented within providers which you can register with Minion using the register($provider) method. A provider can be the name of a class (full namespace if applicable) or a Closure.

Consider the following directory structure:

src/
vendor/
start.php
composer.json

Provider Classes

  • Provider classes is where your application logic resides, Minion uses topic prefixes as a convention to distinguish providers and that is done by specifying a protected $prefix = 'topic.prefix.'; in your provider class.

It is a convention to use dot '.' separated prefixes such as chat. which will result in topic read end up being chat.read

  • Every provider class must extend Vinelab\Minion\Provider and implement public function boot() method which is the best place to have your registrations and pub/sub operations.

  • Every method registered or subscribed will receive the $args and $data when involved. Consider this method

    public function get($args, $data)
    • $args is the array of the args passed from the call
    • $data is a Dictionary instance where you can safely access attributes like $data->something and when they don't exist you get a null value instead of an error as in StdClass objects, though you may use the $data variable as you would use any other object with isset($data->prop) and empty($data->prop)
  • src/ChatProvider.php

<?php

use Vinelab\Minion\Provider;

class ChatProvider extends Provider
{
    protected $prefix = 'chat.';

    public function boot()
    {
        // will be registered to topic: chat.send
        $this->register('send', 'sendMessage');
    }

    public function sendMessage($args, $data)
    {
        $message = $data->message;

        // store message in the database

        // tell everyone about it
        $this->publish('message', compact('message'));

        // response with the status
        return true;
    }
}
  • start.php
use Vinelab\Minion\Minion;

$m = new Minion;
$m->register('ChatProvider');
$m->run();

Closures as Providers

  • start.php
require __DIR__.'/vendor/autoload.php'

use Vinelab\Minion\Minion;
use Vinelab\Minion\Client;

// Get a minion instance
$m = new Minion;

$add = function ($x, $y) { return $x + $y; };

// Register a closure provider
$m->register(function (Client $client) use ($add) {

    // register
    $client->register('add', $add);

    // subscribe
    $client->subscribe('some.topic', function ($data) {
        // do things with data
        $data->key;
        $data->other_key;
    });

    // publish
    $client->publish('i.am.here', ['name' => 'mr.minion']);
});

CLI

Minion comes with a handy command line tool for usage straight from the command line. Once you install using composer a minion binary will be in your vendor/bin/. To make things easier you can run export PATH="./vendor/bin:$PATH" to use minion run straight instead of ./vendor/bin/minion run

use minion list for a list of available commands and minion --help [command] for more info about each of them.

Commands
  • run
    • Options
      • --realm: Specify WAMP realm to be used
      • --host: Specify the router host
      • --port: Specify the router port
      • --register: Register provider classes (can be used multiple times)
    • Example minion run --realm=chatting --port=9876 --register="ChatProvider" --register="MyApp\Providers\NotificationsProvider"

Crossbar.io

Minion ships with a minimal crossbar.io config file which you can find at ./vendor/vinelab/minion/.crossbar/config.json and to start crossbar using it run crossbar start --cbdir ./vendor/vinelab/minion/.crossbar

To get started with Crossbar visit the Quick Start with Crossbar.io Guide.

For more information about crossbar head over to Crossbar.io Quick Start.

Contributing

Pull Requests are most welcome! Dev packages are specified in composer.json under require-dev

  • Run tests with ./vendor/bin/phpunit
  • Coding standards must be checked before committing code by issuing: ./vendor/bin/phpcs --standard=phpcs.xml src
  • In the case of violations use ./vendor/bin/php-cs-fixer fix src which will help solve them out

License

Minion is distributed under the MIT License, see the LICENSE file in this package.

vinelab/minion 适用场景与选型建议

vinelab/minion 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.45k 次下载、GitHub Stars 达 127, 最近一次更新时间为 2014 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「websocket」 「real-time」 「laravel」 「realtime」 「minion」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 vinelab/minion 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vinelab/minion 我们能提供哪些服务?
定制开发 / 二次开发

基于 vinelab/minion 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 127
  • 点击次数: 37
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 127
  • Watchers: 11
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-22