当前位置:网站首页>php+swoole
php+swoole
2022-07-27 04:14:00 【Fragrant orange and treasure orange linger】
<?php
// establish WebSocket Server object , monitor 0.0.0.0:9502 port
$ws = new Swoole\WebSocket\Server('0.0.0.0', 9502);
$redis = new Redis();
$redis->connect('127.0.0.1','6379');
// monitor WebSocket Connection open event
$ws->on('Open', function ($ws, $request) {
echo $request->fd." Successful connection ";
});
// monitor WebSocket News events
$ws->on('Message', function ($ws, $frame)use($redis) {
$data = json_decode($frame->data,true);
switch ($data['type']) {
case 'open':
$redis->set($data['my'],$frame->fd);
break;
case 'send':
$to = $redis->get($data['to']);
$msg = [
'msg'=>$data['msg']
];
$ws->push($to,json_encode($msg,true));
break;
default:
// code...
break;
}
});
// monitor WebSocket Connection close event
$ws->on('Close', function ($ws, $fd) {
echo "client-{$fd} is closed\n";
});
$ws->start();
边栏推荐
- Use tag tag in golang structure
- 2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作
- Lixia action | Yuanqi Digitalization: existing mode or open source innovation?
- 【obs】动态码率:码率估算
- Notes are a little fun
- Restful Fast Request 2022.2.2发布,支持批量导出文档
- The 100th of the commercial anti counterfeiting series - boring systems and management processes can really be thrown into the trash can - by the way, analyze a dozen useless unity game self-test proj
- The problem that prevented the installation of umi4 for one day has been solved
- scala 不可变Map 、 可变Map 、Map转换为其他数据类型
- A. Round Down the Price
猜你喜欢

C语言学习笔记 —— 内存管理

电商系统结合商品秒杀活动,VR全景不断带来收益

2022年危险化学品经营单位主要负责人复训题库及答案

Restful fast request 2022.2.2 release, supporting batch export of documents

288 page 180000 word intelligent campus overall design directory

452页13万字现代智慧乡镇雪亮工程整体解决方案2022版
![[MySQL series] MySQL index transactions](/img/85/04eb67471ba1348af2a26bc4621c65.png)
[MySQL series] MySQL index transactions

记一次TCP丢包带来的重大性能问题

C how to set different text watermarks for each page of word

科目三: 济南章丘三号线
随机推荐
括号的最大嵌套深度
Parallel desktop startup virtual machine "operation failed" problem solution
First pass of routing strategy
什么是动画效果?什么是过渡效果?
The real digital retail should have richer connotation and significance
搜索旋转排序数组
Interview question 16.05 factorial mantissa
288页18万字智能化校园总体设计 目录
A. Parkway Walk
BigDecimal踩坑总结&最佳实践
想要获得 Apache 官方域名邮箱吗?专访 Apache Linkis 五位新晋 Committer告诉你怎么做
356页14万字高端商业办公综合楼弱电智能化系统2022版
对NIO的初步理解
Framework learning journey: init process startup process
JS array de duplication (including simple array de duplication and object array de duplication)
3381. Mobile keyboard (Tsinghua University postgraduate entrance examination machine test question)
暑假加餐|有钱人和你想的不一样(第5天)+电力系统潮流仿真(文档和Matlab代码)
Big talk · book sharing | lean product development: principles, methods and Implementation
手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
A. YES or YES?