Thruway

用于 Autobahn 和 WAMP(web 应用消息传递协议)的 PHP 客户端和路由器库,用于实时应用消息传递。「PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging」

Github星跟踪图

Build Status

Thruway

Thruway is an open source client and router implementation of WAMP (Web Application Messaging Protocol), for PHP. Thruway uses an event-driven, non-blocking I/O model (reactphp), perfect for modern real-time applications.

Supported WAMP Features

Basic Spec read more

  • Publish and Subscribe
  • Remote Procedure Calls
  • Websocket Transport
  • Internal Transport*
  • JSON serialization

Advanced Spec read more

  • RawSocket Transport
  • Authentication
  • WAMP Challenge-Response Authentication
  • Custom Authentication Methods
  • Authorization
  • Publish & Subscribe
  • Subscriber Black and Whitelisting
  • Publisher Exclusion
  • Publisher Identification
  • Subscriber Meta Events
  • Event History*
  • Subscription Matching
  • Prefix matching
  • Remote Procedure Calls
  • Caller Identification
  • Progressive Call Results
  • Distributed Registrations & Calls*
  • Caller Exclusion
  • Canceling Calls

* Thruway specific features

Requirements

Thruway is only supported on PHP 5.6 and up.

Quick Start with Composer

Create a directory for the test project

  $ mkdir thruway

Switch to the new directory

  $ cd thruway

Download Composer more info

  $ curl -sS https://getcomposer.org/installer | php

Download Thruway and dependencies

  $ php composer.phar require voryx/thruway

If you're going to also use the Thruway Client install a client transport. You'll need this to run the examples

  $ php composer.phar require thruway/pawl-transport

Start the WAMP router

  $ php vendor/voryx/thruway/Examples/SimpleWsRouter.php

Thruway is now running on 127.0.0.1 port 9090

PHP Client Example

<?php

require __DIR__ . '/vendor/autoload.php';

use Thruway\ClientSession;
use Thruway\Peer\Client;
use Thruway\Transport\PawlTransportProvider;

$client = new Client("realm1");
$client->addTransportProvider(new PawlTransportProvider("ws://127.0.0.1:9090/"));

$client->on('open', function (ClientSession $session) {

    // 1) subscribe to a topic
    $onevent = function ($args) {
        echo "Event {$args[0]}\n";
    };
    $session->subscribe('com.myapp.hello', $onevent);

    // 2) publish an event
    $session->publish('com.myapp.hello', ['Hello, world from PHP!!!'], [], ["acknowledge" => true])->then(
        function () {
            echo "Publish Acknowledged!\n";
        },
        function ($error) {
            // publish failed
            echo "Publish Error {$error}\n";
        }
    );

    // 3) register a procedure for remoting
    $add2 = function ($args) {
        return $args[0] + $args[1];
    };
    $session->register('com.myapp.add2', $add2);

    // 4) call a remote procedure
    $session->call('com.myapp.add2', [2, 3])->then(
        function ($res) {
            echo "Result: {$res}\n";
        },
        function ($error) {
            echo "Call Error: {$error}\n";
        }
    );
});


$client->start();

Javascript Clients

You can also use AutobahnJS or any other WAMPv2 compatible client.

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

Here's a plunker that will allow you to run some tests against a local router

For AngularJS on the frontend, use the Angular WAMP wrapper.

主要指标

概览
名称与所有者voryx/Thruway
主编程语言PHP
编程语言PHP (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2014-06-12 22:49:49
推送于2022-02-18 06:48:10
最后一次提交2022-02-18 01:45:43
发布数33
最新版本名称0.6.1 (发布于 )
第一版名称0.1.0 (发布于 2014-07-07 15:06:54)
用户参与
星数680
关注者数46
派生数123
提交数552
已启用问题?
问题数298
打开的问题数24
拉请求数33
打开的拉请求数10
关闭的拉请求数23
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?