fanout/laravel-fanout 问题修复 & 功能扩展

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

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

fanout/laravel-fanout

最新稳定版本:1.2.0

Composer 安装命令:

composer require fanout/laravel-fanout

包简介

Fanout.io library for Laravel.

README 文档

README

Author: Konstantin Bokarius kon@fanout.io

Fanout.io library for Laravel.

Credit

This project is based on the following pull request by Christopher Thomas: https://github.com/cwt137/laravel-framework/commit/b64b57ec0dfac975db9fadecac9f7a3757b7af30

Requirements

  • openssl
  • curl
  • pthreads (required for asynchronous publishing)
  • php >=7.0.0
  • laravel >= 5.5
  • fanout/fanout >=2.0.0 (retrieved automatically via Composer)

Installation

Using Composer:

composer require fanout/laravel-fanout

Manual: ensure that php-fanout has been included and require the following files in laravel-fanout:

require 'laravel-fanout/src/fanoutbroadcaster.php';
require 'laravel-fanout/src/fanoutbroadcastserviceprovider.php';

Asynchronous Publishing

In order to make asynchronous publish calls pthreads must be installed. If pthreads is not installed then only synchronous publish calls can be made. To install pthreads recompile PHP with the following flag: '--enable-maintainer-zts'

Also note that since a callback passed to the publish_async methods is going to be executed in a separate thread, that callback and the class it belongs to are subject to the rules and limitations imposed by the pthreads extension.

See more information about pthreads here: http://php.net/manual/en/book.pthreads.php

Usage

In your config/broadcasting.php file set the default driver to 'fanout' and add the connection configuration like so:

'default' => 'fanout',

'connections' => [
    ...
    'fanout' => [
        'driver' => 'fanout',
        'realm_id' => '<my-realm-id>',
        'realm_key' => '<my-realm-key>',
        'ssl' => true,
        'publish_async' => false
    ],
    ...
]

In your config/app.php file add the following provider to your service providers array:

'providers' => [
    ...
    LaravelFanout\FanoutBroadcastServiceProvider::class,
    ...
]

Add a custom broadcast event to your application like so:

namespace App\Events;

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

class PublishToFanoutEvent implements ShouldBroadcast
{
    use SerializesModels;

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return ['<channel>'];
    }
}

Now to publish to Fanout.io in your application simply fire the event:

event(new App\Events\PublishToFanoutEvent('Test publish!!'));

统计信息

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

GitHub 信息

  • Stars: 11
  • Watchers: 6
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-20