eole/sandstone
Composer 安装命令:
composer require eole/sandstone
包简介
Silex RestApi with Websockets.
README 文档
README
PHP microframework designed to build a RestApi working together with a websocket server.
Build a real time RestApi!
💬 New (18 April 2018)
I opened a chat channel where you can get help, give feedback, and talk about Sandstone (Mattermost instance):
💬 https://framateam.org/sandstone 💬
Install
composer require eole/sandstone
Usage
Create a Sandstone application
Sandstone is a Silex application with websockets:
$app = new Eole\Sandstone\Application();
Declare a websocket topic
Similar as declaring a Silex route:
$app->topic('chat/{channel}', function ($topicPattern, $arguments) { $channelName = $arguments['channel']; return new ChatTopic($topicPattern, $channelName); });
See ChatTopic class here.
Send push notifications
When an endpoint is called on the RestApi, i.e POST /api/articles and update a resource,
you can send a push notification to notify this update.
On the RestApi stack:
use Symfony\Component\HttpFoundation\Response; $app->post('api/articles', function () use ($app) { // Dispatch an event on article creation $app['dispatcher']->dispatch('article.created', new ArticleEvent()); return new Response([], 201); }); // Send all 'article.created' events to push server $app->forwardEventToPushServer('article.created');
Then on the websocket stack:
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Eole\Sandstone\Websocket\Topic; class MyWebsocketTopic extends Topic implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ 'article.created' => 'onArticleCreated', ]; } public function onArticleCreated(ArticleEvent $event) { $this->broadcast([ 'message' => 'An article has just been published: '.$event->title, ]); } }
Examples
Working examples from scratch:
Documentation
See the full documentation here
Sandstone edition
You're planning to start a new real-time Rest Api application based on Sandstone?
You may be interested by Sandstone edition.
It already integrates a Sandstone application with a docker environment, a database, debug tools...
Get started with Sandstone edition.
Misc
Articles about Sandstone:
- Sandstone explained to NodeJS, Python or PHP users
- Creating a poker planning application with PHP and websockets
- What is Sandstone, What can I do with Sandstone
Big picture: https://eole-io.github.io/sandstone-doc/big-picture
Changelog
See Releases page.
License
This library is under MIT License.
eole/sandstone 适用场景与选型建议
eole/sandstone 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.21k 次下载、GitHub Stars 达 111, 最近一次更新时间为 2016 年 06 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「silex」 「symfony」 「php」 「websocket」 「push」 「reactphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eole/sandstone 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eole/sandstone 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eole/sandstone 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
Object-oriented CRUD for Doctrine DBAL
Command bus implementation: Commands and domain events
Pomm service provider for the Silex µframwork.
Bundle Symfony DaplosBundle
Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
统计信息
- 总下载量: 5.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 112
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-15
