当前位置:网站首页>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();
边栏推荐
- Bean Validation原理篇--07
- Is VR panorama just needed now? After reading it, you will understand
- 0726~简历梳理面试总结
- 【MySQL系列】MySQL索引事务
- 11.zuul路由网关
- Golang sends email to the mail Library
- 288页18万字智能化校园总体设计 目录
- 452 pages, 130000 words, the overall solution of modern smart Township Xueliang project 2022 Edition
- 零基础小白也能懂的 Redis 数据库,手把手教你易学易用!
- 【SemiDrive源码分析】【驱动BringUp】41 - LCM 驱动 backlight 背光控制原理分析
猜你喜欢

tcp协议知识详解

Development of NFT digital collection system: Xiaoyi digital intelligence helps brands launch NFT with one click on the chain

"Gonna be right" digital collection is now on sale! Feel the spiritual resonance of artists

Startup process and rescue mode

11. Zuul routing gateway

VR全景人淘金“小心机”(上)

Detailed analysis of trajectory generation tool in psins toolbox

E-commerce system combined with commodity spike activities, VR panorama continues to bring benefits

VR全景制作在家装行业是谈单利器?这是为什么呢?

Lixia action | Yuanqi Digitalization: existing mode or open source innovation?
随机推荐
288页18万字智能化校园总体设计 目录
记一次TCP丢包带来的重大性能问题
Framework learning journey: init process startup process
2022危险化学品生产单位安全生产管理人员考试题模拟考试题库模拟考试平台操作
【obs】动态码率:码率估算
Sum of binary numbers from root to leaf
JMeter interface test (login, registration)
JS to realize page Jump and parameter acquisition and loading
Chapter 4 decision tree and random forest
0726~简历梳理面试总结
[semidrive source code analysis] [drive bringup] 41 - LCM drive backlight backlight control principle analysis
Use tag tag in golang structure
技术分享 | 需要小心配置的 gtid_mode
Subject 3: Jinan Zhangqiu line 5
对NIO的初步理解
2022 retraining question bank and answers for main principals of hazardous chemical business units
Redis (IX) - redis distributed lock
H. 265 web player easyplayer's method of opening video to the public
Apachecon Asia preheating live broadcast incubator theme full review
Summer meal | rich people are different from what you think (day 5) + power system power flow simulation (documents and matlab code)