承接 cmosguy/laravel-http-pushstream-broadcaster 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

cmosguy/laravel-http-pushstream-broadcaster

Composer 安装命令:

composer require cmosguy/laravel-http-pushstream-broadcaster

包简介

Laravel broadcast driver for the HTTP Push-stream Nginx module

README 文档

README

Thank your for your interest in the HTTP Push-stream Nginx broadcast driver for Laravel. If you are here, it is because you are trying to leverage the latest feature within the Laravel 5.1 broadcasts events for websockets. The HTTP Pushstream Module for Nginx is a powerful Websocket system.

Why use HTTP Pushstream?

If you want to really absorb the power of the capabilities of this module then check out what the dev-ops from Disqus thought in this link:

http://highscalability.com/blog/2014/4/28/how-disqus-went-realtime-with-165k-messages-per-second-and-l.html

How does this driver work?

Once you setup all your routes for the pub/sub requests to the HTTP routes in the location directives for Nginx, then you'll be able to quickly open a socket on your client use the pushstream.js and push your broadcasts out using websocket or long-polling.

The pub/sub requests are internally called by the GuzzleHttp package. The broadcasting.php config file will use the pushstream driver where you can control the HTTP requests to the to your pub/sub endpoints.

You can lock down your pub/sub nginx endpoints using the Access Key Module. Here you can configure the key.

Requirements

Installation

  1. Do a composer require get this package: composer require cmosguy/laravel-http-pushstream-broadcaster

  2. Next, go into your config/broadcasting.php file and add the following lines accordingly. base_url refers to websocket root for your HTTP requests pub/sub routes:

     'default' => 'pushstream',
    
     'pushstream' => [
         'driver' => 'pushstream',
         'base_url' => 'http://localhost',
         'access_key' => md5('foo'),
         'cert' => null
         // or 'cert' => 'path/to/server.crt' for self-signed certificate
     ]
    
  3. In your config/app.php add the following line to your providers array:

    'Cmosguy\Broadcasting\PushStreamBroadcastManagerProvider'
    

Sample Nginx Configuration

  1. In your /etc/nginx/nginx.conf file add:

    push_stream_shared_memory_size 32M;
    
  2. Edit your config file for your routes in the server { section. Obviously, you need to understand and modify the items below. The following config information is just meant to get you started. If you want a more thorough config check out this:

    location /channels-stats {
        # activate channels statistics mode for this location
        push_stream_channels_statistics;
    
        # query string based channel id
        push_stream_channels_path               $arg_id;
    }
    
    location /pub {
       # activate publisher (admin) mode for this location
       push_stream_publisher admin;
    
        # query string based channel id
        push_stream_channels_path               $arg_id;
    }
    
    location ~ /sub/(.*) {
        # activate subscriber (streaming) mode for this location
        push_stream_subscriber;
    
        # positional channel path
        push_stream_channels_path                   $1;
    }
    
    location ~ /ws/(.*) {
        # activate websocket mode for this location
        push_stream_subscriber websocket;
    
    
        # positional channel path
        push_stream_channels_path                   $1;
        if ($arg_tests = "on") {
          push_stream_channels_path                 "test_$1";
        }
    
        # store messages in memory
        push_stream_store_messages              on;
    
        push_stream_websocket_allow_publish     on;
    
        if ($arg_qs = "on") {
          push_stream_last_received_message_time "$arg_time";
          push_stream_last_received_message_tag  "$arg_tag";
          push_stream_last_event_id              "$arg_eventid";
        }
    }
    

Locking down the pub/sub endpoint

    location /pub {
       # activate publisher (admin) mode for this location
       push_stream_publisher admin;
       accesskey                on;
       accesskey_hashmethod     md5;
       accesskey_arg            "access_key";
       accesskey_signature      "foo"

        # query string based channel id
        push_stream_channels_path               $arg_id;
    }

Usage in your app

So, once you are finally ready to trigger an event, you can do this easily now by just extending this broadcastOn in your event handler:

<?php namespace App\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class SomeEvent implements ShouldBroadcast
{
    use SerializesModels;
    /**
     * @var Foo
     */
    public $foo;

    public function __construct(Foo $foo)
    {
        //
        $this->foo = $foo;
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['foochannel-'.$this->foo->uuid];
    }
}

The Client

Please download the pushstream.js from either following locations:

Study the Push Stream Module

At this time the only way to get more information from about the module and the capabilities is directly from the github repository, so do some reading here:

Disclaimer

This is by no means the only way to go about how this should work. You need to understand what all the options do and there is definitely a a

Help

Please help me with updating this documentation. If it does not make sense or if you see something stupid let me know. Also, if there is a way to make this extend further and make it more flexible for others, please submit a PR to improve upon these.

cmosguy/laravel-http-pushstream-broadcaster 适用场景与选型建议

cmosguy/laravel-http-pushstream-broadcaster 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 287 次下载、GitHub Stars 达 201, 最近一次更新时间为 2015 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 cmosguy/laravel-http-pushstream-broadcaster 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cmosguy/laravel-http-pushstream-broadcaster 我们能提供哪些服务?
定制开发 / 二次开发

基于 cmosguy/laravel-http-pushstream-broadcaster 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 201
  • Watchers: 11
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-29