1 Star 0 Fork 3

RoseKissYou / socket-io

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

请暂时不要用于生产环境

项目还在开发优化中

Socket-IO

再次升级,此版本采用hyperf2.x+Vue+Element搭建的分布式Socket-io系统,利用rpc作为注册,鉴权服务,rpc发布到注册中心.利用dao-cloud+docker多容器部署目前已初步搭建完成,待完成系统业务会继续优化,写份教程供大家学习. 此次系统的业务逻辑借鉴lumen-im 的逻辑用hyperf重写,第一版本求稳定运行上线.第二版本会重新整理业务架构,代码更加优化。更加符合PHP规范化.

Socket-IO服务聊天系统

Php Version Swoole Version sl-im License

简介

socket-io 是基于 Hyperf 微服务协程框架(Swoole)和 Vue + ElementUI 网页聊天系统 所开发出来的聊天室。

体验地址

Socket-IO

功能

1.0

  • 基于Swoole Socket-io服务做消息即时推送
  • 支持私聊及群聊
  • 支持聊天消息类型有文本、代码块、图片及其它类型文件,并支持文件下载
  • 支持聊天消息撤回、删除或批量删除、转发消息(逐条转发、合并转发)
  • 支持docker部署(后续写搭建教程)
  • Rpc服务注册登录鉴权
  • Nsq分布式消息中间件
  • Mysql提供数据存储功能
  • Redis存储聊天关系映射

问题

Json-Rpc 业务架构比较混乱和Service层架构冲突。下个版本着重优化,把HTTP和Rpc部分业务分到Service层. 代码规范不符合现代化.有重复的代码使用.socket-io服务单独重构独立成为分布式服务 也许它存在很多问题,但是也请大家多一份耐心,毕竟一个人的开发精力有限。项目我会一直维持下去。 也希望证明php也是可以做分布式的。恢复php荣光,我辈义不容辞.

2.0

  • 重新架构
  • 代码更符合PHP标准化

Requirement

单机部署方式

Composer

composer install

env配置

APP_NAME=skeleton
APP_ENV=dev

DB_DRIVER=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=hyperf
DB_USERNAME=root
DB_PASSWORD=
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci
DB_PREFIX=

REDIS_HOST=localhost
REDIS_AUTH=(null)
REDIS_PORT=6379
REDIS_DB=0

CLOUD_REDIS=default

WEBSOCKET_SERVER_IPS = {"ws1":"127.0.0.1","ws2":"127.0.0.2"}
AMQP_HOST=localhost //rabbitmq地址
NSQ_HOST=localhost //nsq地址
CONSUL_HOST=localhost:8500 //consul地址
NSQD_HOST=127.0.0.1:4151 //nsqd地址

//邮箱配置
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_FROM=
MAIL_NAME=
//静态资源地址
IMAGE_URL=http://127.0.0.1:9500
//七牛配置
QINIU_ACCESS_KEY=
QINIU_SECRET_KEY=
QINIU_BUCKET=
QINBIU_DOMAIN=

nginx配置

# 至少需要一个 Hyperf 节点,多个配置多行
upstream hyperf_chat_http {
    # Hyperf-Chat HTTP Server 的 IP 及 端口
    server 127.0.0.1:9500;
    server 127.0.0.1:1500;
}
upstream hyperf_chat_ws {
    # 设置负载均衡模式为 IP Hash 算法模式,这样不同的客户端每次请求都会与同一节点进行交互
    ip_hash;
    # Hyperf Chat Server 的 IP 及 端口
    server 127.0.0.1:9502;
    server 127.0.0.1:1502;
}
server {
    listen 443 ssl;
    index index.html index.htm;
    server_name xxx.cn;
  error_log /home/wwwlogs/xxxerr.log;
    root /home/wwwroot/hyperf-chat/public;
    ssl_certificate /etc/ssl/xxx.crt;
    # 指定私钥文件路径
    ssl_certificate_key /etc/ssl/xxx.key;
    ssl_protocols        TLSv1.2 TLSv1.1 TLSv1;
        ssl_ciphers   ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers   on;
        ssl_session_timeout 5m;
      index index.php index.html index.htm;
    location / {
        # 将客户端的 Host 和 IP 信息一并转发到对应节点
           proxy_set_header Host $http_host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

               # 转发Cookie,设置 SameSite
           proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";

               # 执行代理访问真实服务器
           proxy_pass http://hyperf_chat_http;
    }
    location /socket.io {
        # WebSocket Header
         proxy_http_version 1.1;
         proxy_set_header Upgrade websocket;
         proxy_set_header Connection "Upgrade";

         # 将客户端的 Host 和 IP 信息一并转发到对应节点
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header Host $http_host;

         # 客户端与服务端无交互 60s 后自动断开连接,请根据实际业务场景设置
         proxy_read_timeout 60s ;

               # 执行代理访问真实服务器
         proxy_pass http://hyperf_chat_ws;
    }
}
server
{
  # 80端口是http正常访问的接口
  listen 80;
  server_name xxx.cn;
  # 在这里,我做了https全加密处理,在访问http的时候自动跳转到https
  rewrite ^(.*) https://$host$1 permanent;
}

Start

  • 挂起
composer dump-autoload -o
php bin/hyperf.php start

打赏(你的支持是我最大的动力)

联系方式

  • WeChat:naicha_1994
  • QQ:847050412
  • QQ群:658446650

socket-io欢迎star

socket-io

License

LICENSE

MIT License Copyright (c) 2020 Hyperf-Glory Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

hyperf_chat升级版 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/RoseKissYou/socket-io.git
git@gitee.com:RoseKissYou/socket-io.git
RoseKissYou
socket-io
socket-io
master

搜索帮助