• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Simplified Client for WAMP v2 (Web Application Messaging Protocol) with command line support - PHP WebSocket Made Easy

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.

More Repositories

1

NeoEloquent

The Neo4j OGM for Laravel
PHP
640
star
2

cdn

CDN Assets Manager Package for Laravel.
PHP
212
star
3

tracing-laravel

Distributed tracing (OpenTracing) for Laravel made easy
PHP
77
star
4

url-shortener

Shorten your URL the easy way, with your favourite provider (Bit.ly, Goo.gl, Ow.ly).
PHP
59
star
5

http

A smart, simple and fault-tolerant HTTP client for sending and receiving JSON and XML
PHP
57
star
6

laravel-editor

Markdown Text Editor (WYSIWYG) with social network embeds support and a nifty json output
PHP
53
star
7

RSS

Simple RSS Client
PHP
48
star
8

bowler

RabbitMQ wrapper for Laravel
PHP
45
star
9

api-manager

Api manager you won't hate. Beautify and unify your responses with the least effort possible.
PHP
38
star
10

ansible-composer

Install PHP Composer on Centos/Red Hat with Ansible
34
star
11

agency

A Neo4j (graph db based) content management system built with smart tools and compelling UI for the 21st century.
JavaScript
21
star
12

youtube

Fetch & sync videos and channels from Youtube API V3
PHP
16
star
13

iTunes

A simple yet full-fledged iTunes API client with caching support.
PHP
13
star
14

docker-nginx-php

A PHP application image with NGINX as a web server monitored by supervisord
Dockerfile
12
star
15

docker-php-mongo

PHP-FPM with MongoDB extension installed
10
star
16

social-auth

Social network authentication package
PHP
10
star
17

ansible-supervisor

An Ansible playbook role to install supervisord on CentOS/Red Hat/Fedora
10
star
18

mr-uploader

jQuery plugin for simplified photo cropping and uploading.
JavaScript
9
star
19

docker-hhvm

A docker image to run Laravel apps under Facebook's HHVM compiler in FastCGI mode behind an NGINX web server.
Shell
8
star
20

Android-wamp-client

Android client for WAMP v2 (Web Application Messaging Protocol) based on Jawampa library
Java
8
star
21

node-promise-cache

A promise-based cache store that preserves stored data types and is easily expandable with custom cache stores
CoffeeScript
8
star
22

ansible-redis

Install and configure Redis on Centos/Red Hat with Ansible
7
star
23

ansible-mongodb

Install MongoDB with Ansible on Centos/Red Hat
6
star
24

ansible-mysql

Install and configure MySQL on Centos/Red Hat with Ansible
5
star
25

docker-neo4j

An image to run a Neo4j container
Shell
5
star
26

ansible-haproxy

Install HAProxy on Centos/Red Hat with Ansible
4
star
27

assistant

Bunch of helper classes
PHP
4
star
28

docker-php-fpm

Run PHP FastCGI with common extensions out of the box
4
star
29

ansible-nginx-laravel

Ansible role for nginx with configuration for Laravel
4
star
30

ansible-docker

Install Docker on CentOS and Red Hat hosts. Used to enable the use of Ansible's Docker module.
4
star
31

tracing-go

Distributed tracing (OpenTracing) for Go made easy
Go
3
star
32

generator-tom

Yeoman Generator for AngularJS Apps in CoffeeScript
CoffeeScript
3
star
33

haproxy-config-manager

API built on Django Rest Framework to make scaling using HAProxy LB much easier.
Python
3
star
34

agency-deployment-provisioning

The server cluster provisioning of Agency for development and production using Ansible.
Shell
3
star
35

herald

Backend engineering code test.
PHP
2
star
36

country

PHP
2
star
37

docker-redis

A redis image suitable for production use
Shell
2
star
38

docker-base

A base image that allows simple ssh access through ssh keys
Shell
2
star
39

docker-laravel

Run Laravel projects using Docker and Nginx
2
star
40

ansible-deploy

Deploy Git repos to remote hosts using configurable SSH Keys
2
star
41

iTunes-distribution-metadata-generator

iTunes distribution metadata generator
PHP
2
star
42

go-init

An initial structure for building Go web apps.
Go
2
star
43

ansible-php-mongo

Install MongoClient class for PHP on Centos/Red Hat with Ansible
2
star
44

ecs-watchtower

ECS Watchtower is a health check script with a status page for AWS ECS tasks
JavaScript
1
star
45

php-coding-standards

PHP Coding Standards
1
star
46

yoda-prototype

PHP
1
star
47

flickr

PHP
1
star
48

oauth-clients-generator-redis

Redis Client Generator for the League's PHP OAuth 2.0 server
PHP
1
star
49

sample-laravel-testing-workflow

The code of the morning session on Friday 23-May-2014 in Cloud 5 introducing a better workflow with integration tests right from the kick off of the project
PHP
1
star
50

oclock

OClock is a Laravel schedules explorer
PHP
1
star
51

socialite-android

Light integration of social plugins on Android like login and sharing
Java
1
star
52

acid

Advanced content user-interface displayer
1
star
53

ansible-php-fpm

Install php-fpm with Ansible on Centos/Red Hat
1
star
54

nginx-basic-auth

NGINX with configurable basic auth using ENV vars
Shell
1
star