PHPackages                             mateusz-wilk/thruway-bundle - 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. mateusz-wilk/thruway-bundle

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

mateusz-wilk/thruway-bundle
===========================

WebSockets (WAMP2) integration for Symfony2

0.1.0(10y ago)088MITPHPPHP &gt;=5.4

Since Feb 20Pushed 10y ago1 watchersCompare

[ Source](https://github.com/MateuszWilk/ThruwayBundle)[ Packagist](https://packagist.org/packages/mateusz-wilk/thruway-bundle)[ RSS](/packages/mateusz-wilk-thruway-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (8)Versions (7)Used By (0)

ThruwayBundle
=============

[](#thruwaybundle)

This a Symfony Bundle for [Thruway](https://github.com/voryx/Thruway), which is a php implementation of WAMP (Web Application Messaging Protocol).

Note: This project is still undergoing a lot of changes, so the API will change.

### Quick Start with Composer

[](#quick-start-with-composer)

Install the Thruway Bundle

```
  $ php composer.phar require "voryx/thruway-bundle":"dev-master"

```

Update AppKernel.php

```
$bundles = array(
    // ...
    new JMS\SerializerBundle\JMSSerializerBundle(),
    new Voryx\ThruwayBundle\VoryxThruwayBundle($this),
    // ...
);
```

### Configuration

[](#configuration)

```
#app/config/config.yml

voryx_thruway:
    realm: 'realm1'
    url: 'ws://127.0.0.1:8081' #The url that the clients will use to connect to the router
    router:
        ip: '127.0.0.1'  # the ip that the router should start on
        port: '8080'  # public facing port.  If authentication is enabled, this port will be protected
        trusted_port: '8081' # Bypasses all authentication.  Use this for trusted clients.
#        authentication: false # true will load the AuthenticationManager
    locations:
        bundles: ["AppBundle"]
#        files:
#            - "Acme\\DemoBundle\\Controller\\DemoController"
    serializer: # allow to set JMS_Serializer parameters - for now only serialize_null
        serialize_null: true

```

If you are using the in-memory user provider, you'll need to add a `thruway` to the security firewall and set the `in_memory_user_provider`.

```
#app/config/security.yml

security:
   firewalls:
        thruway:
            security: false
```

You can also tag services with `thruway.resource` and any annotation will get picked up

```

```

### Authentication with FOSUserBundle via WampCRA

[](#authentication-with-fosuserbundle-via-wampcra)

Change the Password Encoder (tricky on existing sites) to master wamp challenge

```
#app/config/security.yml

security:
    ...
    encoders:
        FOS\UserBundle\Model\UserInterface:
            algorithm:            pbkdf2
            hash_algorithm:       sha256
            encode_as_base64:     true
            iterations:           1000
            key_length:           32
```

set voryx\_thruway.user\_provider to "fos\_user.user\_manager"

```
#app/config/config.yml

voryx_thruway:
    user_provider: 'fos_user.user_manager'
```

The WAMP-CRA service is already configured, we just need to add a tag to it to have the bundle install it:

```
    wamp_cra_auth:
        class: Thruway\Authentication\WampCraAuthProvider
        parent: voryx.thruway.wamp.cra.auth.client
        tags:
            - { name: thruway.internal_client }
```

### Custom Authorization Manager

[](#custom-authorization-manager)

You can set your own Authorization Manager in order to check if a user (identified by its authid) is allowed to publish | subscribe | call | register

Create your Authorization Manager service, implementing AuthorizationManagerInterface (see the Thruway doc for details)

```
// src/ACME/AppBundle/Security/MyAuthorizationManager.php

use Thruway\Authentication\AuthorizationManagerInterface;
use Thruway\Message\ActionMessageInterface;
use Thruway\Message\SubscribeMessage;
use Thruway\Session;

class MyAuthorizationManager implements AuthorizationManagerInterface
{
    public function isAuthorizedTo(Session $session, ActionMessageInterface $actionMsg)
    {
        // set here the type of Action you want to check
        // Here it's only Subscribe
        if ($actionMsg instanceof  SubscribeMessage) {
            // Here your own auth rule
            $topic = $actionMsg->getTopicName();
            /* In this example sub patterns meet the following :
             * {userID}.{name}
             * we explode the topic name to get the userID
             */
             $topic = explode('.', $topic);
            if(is_integer($topic[0])){
                  // UserID shall meet AuthID, else deny access
                  if($topic[0] != $session->getMetaInfo()["authid"]){
                        return false;
                  }
            }

        }
        return true;
    }
}
```

Register your authorization manager service

```
     my_authorization_manager:
        class: ACME\AppBundle\Security\MyAuthorizationManager
```

Insert your service name in the voryx\_thruway config

```
#app/config/config.yml

voryx_thruway:
    ...
        authorization: my_authorization_manager # insert the name of your custom authorizationManager
   ...
```

Restart the Thruway server; it will now check authorization upon publish | subscribe | call | register. Remember to catch error when you try to subscribe to a topic (or any other action) as it may now be denied and this will be returned as an error.

Usage
-----

[](#usage)

#### Register RPC

[](#register-rpc)

```
    use Voryx\ThruwayBundle\Annotation\Register;

    /**
     *
     * @Register("com.example.add")
     *
     */
    public function addAction($num1, $num2)
    {
        return $num1 + $num2;
    }
```

#### Call RPC

[](#call-rpc)

```
    public function call($value)
    {
        $client = $this->container->get('thruway.client');
        $client->call("com.myapp.add", [2, 3])->then(
            function ($res) {
                echo $res[0];
            }
        );
    }
```

#### Subscribe

[](#subscribe)

```
     use Voryx\ThruwayBundle\Annotation\Subscribe;

    /**
     *
     * @Subscribe("com.example.subscribe")
     *
     */
    public function subscribe($value)
    {
        echo $value;
    }
```

#### Publish

[](#publish)

```
    public function publish($value)
    {
        $client = $this->container->get('thruway.client');
        $client->publish("com.myapp.hello_pubsub", [$value]);
    }
```

It uses JMS Serializer, so it can serialize and deserialize Entities

```

    use Voryx\ThruwayBundle\Annotation\Register;

    /**
     *
     * @Register("com.example.addrpc", serializerEnableMaxDepthChecks=true)
     *
     */
    public function addAction(Post $post)
    {
        //Do something to $post

        return $post;
    }
```

#### Start the Thruway Process

[](#start-the-thruway-process)

You can start the default Thruway workers (router and client workers), without any additional configuration.

```
$ nohup php app/console thruway:process start &

```

By default, the router starts on ws://127.0.0.1:8080

\##Workers

The Thruway bundle will start up a separate process for the router and each defined worker. If you haven't defined any workers, all of the annotated calls and subscriptions will be started within the `default` worker.

There are two main ways to break your application apart into multiple workers.

1. Use the `worker` property on the `Register` and `Subscribe` annotations. The following RPC will be added to the `posts` worker.

    ```
      use Voryx\ThruwayBundle\Annotation\Register;

      /**
      * @Register("com.example.addrpc", serializerEnableMaxDepthChecks=true, worker="posts")
      */
      public function addAction(Post $post)
    ```
2. Use the `@Worker` annotation on the class. The following annotation will create a worker called `chat` that can have a max of 5 instances.

    ```
      use Voryx\ThruwayBundle\Annotation\Worker;

      /**
      * @Worker("chat", maxProcesses="5")
      */
      class ChatController
    ```

If a worker is shut down with anything other than `SIGTERM`, it will automatically be restarted.

\##More Commands

\#####To see a list of running processes (workers)

```
$ php app/console thruway:process status

```

\#####Stop a process, i.e. `default`

```
$ php app/console thruway:process stop default

```

\#####Start a process, i.e. `default`

```
$ php app/console thruway:process start default

```

### Javascript Client

[](#javascript-client)

For the client, you can use [AutobahnJS](https://github.com/tavendo/AutobahnJS) or any other WAMPv2 compatible client.

Here are some [examples](https://github.com/tavendo/AutobahnJS#show-me-some-code)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.5% 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.

###  Release Activity

Cadence

Every ~72 days

Recently: every ~87 days

Total

6

Last Release

3787d ago

Major Versions

0.1.0 → 1.0.x-dev2016-02-16

PHP version history (2 changes)0.0.1PHP &gt;=5.4

1.0.x-devPHP &gt;=5.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6656055?v=4)[Mateusz Wilk](/maintainers/MateuszWilk)[@MateuszWilk](https://github.com/MateuszWilk)

---

Top Contributors

[![davidwdan](https://avatars.githubusercontent.com/u/4969183?v=4)](https://github.com/davidwdan "davidwdan (98 commits)")[![mbonneau](https://avatars.githubusercontent.com/u/748287?v=4)](https://github.com/mbonneau "mbonneau (5 commits)")[![megazoll](https://avatars.githubusercontent.com/u/347306?v=4)](https://github.com/megazoll "megazoll (5 commits)")[![AchilleAsh](https://avatars.githubusercontent.com/u/3090526?v=4)](https://github.com/AchilleAsh "AchilleAsh (2 commits)")[![eichie](https://avatars.githubusercontent.com/u/917278?v=4)](https://github.com/eichie "eichie (2 commits)")[![Easen](https://avatars.githubusercontent.com/u/111948?v=4)](https://github.com/Easen "Easen (1 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (1 commits)")[![TNAJanssen](https://avatars.githubusercontent.com/u/2812277?v=4)](https://github.com/TNAJanssen "TNAJanssen (1 commits)")[![youmad](https://avatars.githubusercontent.com/u/10434802?v=4)](https://github.com/youmad "youmad (1 commits)")

---

Tags

symfonysocketsWebSocketsWAMPWAMP2Autobahn

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mateusz-wilk-thruway-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/mateusz-wilk-thruway-bundle/health.svg)](https://phpackages.com/packages/mateusz-wilk-thruway-bundle)
```

###  Alternatives

[voryx/thruway-bundle

WebSockets (WAMP2) integration for Symfony2

98120.8k](/packages/voryx-thruway-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[voryx/thruway

Thruway WAMP router core

6751.0M17](/packages/voryx-thruway)[api-platform/symfony

Symfony API Platform integration

384.0M110](/packages/api-platform-symfony)[thruway/client

Thruway WAMP client

11837.2k6](/packages/thruway-client)

PHPackages © 2026

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