PHPackages                             vinelab/minion - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. vinelab/minion

ActiveLibrary[HTTP &amp; Networking](/categories/http)

vinelab/minion
==============

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

v1.4.0(4y ago)1276.4k14[6 issues](https://github.com/Vinelab/minion/issues)[1 PRs](https://github.com/Vinelab/minion/pulls)MITPHPPHP ^7.1 || ^8.0CI failing

Since Nov 27Pushed 4y ago11 watchersCompare

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

READMEChangelog (10)Dependencies (8)Versions (12)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6056edaaa5047014be1f0f685db85dc8b795bb8a04a9f0d952add18d413e19fb/68747470733a2f2f7472617669732d63692e6f72672f56696e656c61622f6d696e696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Vinelab/minion)

[![SensioLabsInsight](https://camo.githubusercontent.com/473a3b408adf6f5d5cbea409de0870b6940a8e86a847c62a8cdcd8c04ab22b4b/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f61656661346661332d653231332d346138312d383733632d3934323737633035353433612f6269672e706e67)](https://insight.sensiolabs.com/projects/aefa4fa3-e213-4a81-873c-94277c05543a)

Minion
======

[](#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](http://github.com/voryx/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](#how-it-works) for details.

For a jump-start head over to the [Quick Start Guide](https://github.com/Vinelab/minion/wiki/Quick-Start-with-Crossbar.io) or read on for detailed docs. Or you may take a look at the [Examples](https://github.com/Vinelab/minion/tree/master/Examples) to get an idea about how this works.

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

[](#installation)

### Composer

[](#composer)

Add the following to `require` in `composer.json`

```
"vinelab/minion": "*"
```

Then run `composer update` to install.

#### Laravel Bounties

[](#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](#cli)
- Run `php artisan vendor:publish` and head to `app/config/minion.php` to configure your minion.

Configuration
-------------

[](#configuration)

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

### Router

[](#router)

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

### Provider Registration

[](#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
-----

[](#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](http://autobahn.ws/js/tutorial.html)

### How It Works

[](#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)

- 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`

```
