virge/stork 问题修复 & 功能扩展

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

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

virge/stork

Composer 安装命令:

composer require virge/stork

包简介

Virge::Stork is a library to help with PHP Based WebSockets, offering an abstraction above Ratchet to provide easy of implementation, horizontally scalable services, and per-topic subscription authentication

README 文档

README

Virge::Stork is a collection of services/components that provide a nice wrapper around Thruway (https://github.com/voryx/Thruway) that provides a horizontally scalable websocket architecture, and per topic subscription authentication for WAMP v2.

Architecture

Virge::Stork provides a scalable architecture that allows you to scale your websocket servers, and webservers independently, as well as support for load balancing of websocket servers.

Publish Server

Virge::Stork provides a ZMQ Publish server. This server subscribes to all available Websocket Servers, and will broadcast every push notification to all websocket servers.

Websocket Client

The websocket client subscribes to the ZMQ Publish server, when receiving messages from the ZMQ Publish Server it broadcasts to all subscribed.

Authentication Client

The Auth Client handles the authentication of clients, and their topic subscriptions.

Crossbar.io or other WAMP Router

Usage requires using crossbar.io or another compliant WAMP Router. Stork depends on a role that allows it to register two Procedures

io.virge.stork.auth Used to provide basic ticket authentication to clients

io.virge.stork.topic_auth Used to determine if the client can subscribe to a given topic

Topics

Topics are a URI that follows the format:

version.feedName.feedId

They are declared in Stork, and optionally attached to verifiers.

use Virge\Stork;
Stork::topic('v1', 'test')
    ->verify(function($session, $topic, $feedId, &$reason) {
        return true;
    })
;

The declared topics do not include the feedId, this is passed in by the client upon connection. It will be passed to the verifier and can be used in determining if the user can subscribe.

Authenticator

Virge::Stork provides the ability to have a custom authenticator callback for initial websocket connection. This authenticator should set the authId to a valid string (usually the UserId of the user connection)

This authId will be used in the topic authentication

Stork::authenticator(function($session, &$returnData) {
    
    if($session->ticket === 'testtest') {
        $returnData['authid'] = "1";
        return true;
    }

    return false;
});

RPC *alpha

Virge::Stork provides the ability to register and call RPC methods. You start with a MethodController that will then register available RPC methods.

Checkout examples/simple/rpc_caller.php and rpc_provider.php for an example.

Running Examples

From within examples/simple you'll need to start 3 processes:

php -f publish_server.php
php -f ws_client.php
php -f auth_client.php

You will also need to start a crossbar.io server, an example configuration is provided within examples/simple:

docker run --name crossbar -p 8000:80 -e "CROSSBAR_BACKEND_SECRET=testtest" -v /abs/path/to/examples/simple/.crossbar:/app/.crossbar --entrypoint "crossbar start --cbdir /app/.crossbar" crossbario/crossbar

We can also start our webserver within that directory:

php -S localhost:9000

Editing services.php will allow you to configure ports, and hostnames.

You should be able to visit http://localhost:9000 and it should attempt to connect to the websocket. Opening up the console will show debug information, and any connection errors.

You can then send push messages using:

php -f push.php

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固