定制 brainboxlabs/brain-socket 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

brainboxlabs/brain-socket

Composer 安装命令:

composer require brainboxlabs/brain-socket

包简介

Websockets for event-driven Laravel apps.

README 文档

README

NOTE: BrainSocket is ideal for heavier front-end development (think single page javascript apps etc). We are currently working on integrating PUSH notifications into the next release.

WebSockets for realtime event-driven Laravel apps.

This Laravel 4 package provides an Artisan command to setup and run a WebSocket server with Ratchet inside of a Laravel app.

Lets begin by installing this package through Composer. Edit your Laravel project's composer.json file and add the require brainboxlabs/brain-socket:

	"require": {
		...
		"brainboxlabs/brain-socket": "v1.0.0"
	},

Note: make sure and check packagist.org for updated dependencies but the list above is what has been tested at the time of this writing.

Once the package and all of its dependencies have been installed we need to add the BrainSocketServiceProvider to our app/config/app.php file.

Add this line:

'providers' => array(
	...
	'BrainSocket\BrainSocketServiceProvider',

to the end of the providers array in the config file.

There is also an optional but recommended Facade you should add to the aliases array in the app/config/app.php file.

'aliases' => array(
	...
	'BrainSocket'     => 'BrainSocket\BrainSocketFacade',

Next open terminal and cd into your Laravel project directory.

run php artisan list and confirm you see the brainsocket: command in the list of commands. It should look like this:

Available commands:
brainsocket
	brainsocket:start

Once you have confirmed the list, run the following command to start the WebSocket server:

php artisan brainsocket:start

Note: The websocket server runs on port 8080 by default. You can change this with the optional --port=port_number on the end of the artisan command.

php artisan brainsocket:start --port=8081

At this point you should see a message in the terminal saying the websocket has been started on the selected port. Terminal will be locked down / unusable at this point, to stop the WebSocket server hit ctrl+c in the terminal.

Note: Any changes to your laravel app / code while the ws server is running are not taken into account. You need to restart the ws server to see any of your changes.

Lets stop the ws server now by hitting ctrl+c in the terminal.

Next in your app/ folder create a file called events.php

Lets add the following code to events.php:

<?php
Event::listen('generic.event',function($client_data){
	return BrainSocket::message('generic.event',array('message'=>'A message from a generic event fired in Laravel!'));
});

Event::listen('app.success',function($client_data){
	return BrainSocket::success(array('There was a Laravel App Success Event!'));
});

Event::listen('app.error',function($client_data){
	return BrainSocket::error(array('There was a Laravel App Error!'));
});

Note: The $client_data parameter passed into the event listener is a POPO (Plain Old PHP Object) with all of the data passed from the client side.

Note: The app.success and app.error events are not required but are helper events for dealing with flash messaging.

Now in app/start/global.php add the following line at the end of the file:

require app_path().'/filters.php';
require app_path().'/events.php';

Great! Now we have a few events to test out on the client side. Run the artisan command php artisan brainsocket:start to start the ws server again.

To make things easier we have created a simple js helper that allows us to interact with our new ws server a bit easier. It's not required but it handles some minor formatting tasks in the background so you don't have to and pairs nicely with our BrainSocket Facade.

Head over to https://github.com/BrainBoxLabs/brain-socket-js to grab it.

brainboxlabs/brain-socket 适用场景与选型建议

brainboxlabs/brain-socket 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40.52k 次下载、GitHub Stars 达 585, 最近一次更新时间为 2013 年 10 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「events」 「WebSockets」 「Ratchet」 「laravel」 「artisan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 brainboxlabs/brain-socket 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 585
  • Watchers: 41
  • Forks: 74
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-10-31