php swoole 和 websocket的初次碰撞
php swoole 扩展仿佛为php开发打开了一扇窗户
php workman和swoole原来是两个东东
- swoole的使用范围更广,能做更多事应该
websocket的介绍
socket 与 websocket也是两个东东
- 阅读文档
- https://blog.csdn.net/hguisu/article/details/7448528
- https://blog.csdn.net/fastjack/article/details/79523363
wss 配置 和 nginx的配置
- wss swoole 服务端
<?php
error_reporting(E_ALL);
set_time_limit(0);
//创建websocket服务器对象,监听0.0.0.0:9502端口
$ws = new swoole_websocket_server("0.0.0.0", 9505, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL);
$config = [
'daemonize' => true,
'ssl_key_file' => '/workspace/file/2191282_www.havetatami.com.key',
'ssl_cert_file' => '/workspace/file/2191282_www.havetatami.com.pem'
];
$ws->set($config);
//监听WebSocket连接打开事件
$ws->on('open', function ($ws, $request) {
var_dump($request->fd);
$ws->push($request->fd, "hello, welcome\n");
});
//监听WebSocket消息事件
$ws->on('message', function ($ws, $frame) {
var_dump($ws->connection_list());
foreach ($ws->connection_list() as $fd){
$ws->push($fd, "server: {$frame->data}");
}
});
//监听WebSocket连接关闭事件
$ws->on('close', function ($ws, $fd) {
echo "client-{$fd} is closed\n";
});
$ws->start();
- wss 浏览器端
<html>
<head>
<meta charset=utf-8 >
<title>test</title>
</head>
<body>
<h3 style="text-align:center;">test</h3>
<script>
var wsServer = 'wss://www.havetatami.com:9502/websocket';
var websocket = new WebSocket(wsServer);
function ssend(){
websocket.send(1);
setTimeout(ssend, 100);
}
websocket.onopen = function (evt) {
console.log("Connected to WebSocket server.");
//ssend();
};
websocket.onclose = function (evt) {
console.log("Disconnected");
};
websocket.onmessage = function (evt) {
console.log('Retrieved data from server: ' + evt.data);
};
websocket.onerror = function (evt, e) {
console.log('Error occured: ' + evt.data);
};
</script>
</body>
</html>
- nginx 配置
server{
listen 443 ssl;
server_name www.havetatami.com;
ssl_certificate /workspace/file/www.havetatami.com.chained.crt;
ssl_certificate_key /workspace/file/www.havetatami.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
root /workspace/web/gitee/havetatami;
location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /workspace/data/nginx/log/www_havetatami_com_access.log;
}
server{
listen 80;
server_name www.havetatami.com;
return 301 https://$server_name$request_uri;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 39.106.58.30:9505;
}
server{
listen 9502 ssl;
server_name www.havetatami.com;
ssl_certificate /workspace/file/2191282_www.havetatami.com.pem;
ssl_certificate_key /workspace/file/2191282_www.havetatami.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
root /workspace/web/gitee/havetatami;
location /websocket {
proxy_pass https://websocket;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
access_log /workspace/data/nginx/log/www_havetatami_com_access1.log;
}
vue-cli,nginx反向代理
- nginx 配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream my_blog {
server localhost:8080;
keepalive 2000;
}
server {
listen 80;
server_name bloghtml.test;
rewrite ^(.*)$ $scheme://www.bloghtml.test$1 permanent;
}
server {
listen 80;
server_name www.bloghtml.test;
client_max_body_size 1024M;
if ($time_iso8601 ~ "^(\d{4}-\d{2}-\d{2})") {
set $ttt $1;
}
access_log /logs/$host-$ttt-access.log main;
root /www/bloghtml/myblog;
location / {
#root /www/bloghtml/myblog;
#index index.php index.html index.htm;
#try_files $uri $uri/ @router;
#proxy_redirect http://my_blog/ http://$host:$server_port/;
#proxy_cookie_path / /;
proxy_pass http://my_blog/;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_connect_timeout 60;
proxy_http_version 1.1;
proxy_set_header Host $host:$server_port;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# location @router {
# rewrite ^.*$ /index.html last;
# }
#location ~* \.php {
# include fastcgi_params;
# fastcgi_index index.php;
# fastcgi_pass localhost:9000;
# fastcgi_split_path_info ^(.+\.php)(.*)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_param SCRIPT_NAME $fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#}
}
- vue 项目根目录下的vue.config.js配置
module.exports = {
devServer: {
open: true,
// host: 'www.bloghtml.test',
https: false,
disableHostCheck: true
}
}
其它参考文档
- https://blog.csdn.net/weixin_42579642/article/details/85266997
- https://www.cnblogs.com/cuishuai/p/9273037.html
- 搜索技术问题谷歌还是更好
- nginx常用代理配置
题外话
- 今天看了书,看到了一句话,安慰自己:一个人愿意让你爱他,就已经是你很大的幸运了。你得好好爱,别辜负了对方的信任和期待。
php swoole 和 websocket的初次碰撞的更多相关文章
- thinkphp 6.0 swoole扩展websocket使用教程
前言 ThinkPHP即将迎来最新版本6.0,针对目前越来越流行Swoole,thinkphp也推出了最新的扩展think-swoole 3.0. 介绍 即将推出的tp6.0,已经适配swoole.并 ...
- 使用swoole和websocket结合来制造弹幕
在知乎上无意中看到了一篇有关这个的话题https://zhuanlan.zhihu.com/p/23992890,刚好没事也好久没弄swoole了就自己按照知乎上的那篇文站实操了一下 那个试验中有几个 ...
- 用swoole和websocket开发简单聊天室
首先,我想说下写代码的一些习惯,第一,任何可配置的参数或变量都要写到一个config文件中.第二,代码中一定要有日志记录和完善的报错并记录报错.言归正传,swoole应该是每个phper必须要了解的, ...
- php 的swoole 和websocket 连接wss
1. 下载证书 $serv = new swoole_server('0.0.0.0', 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL); $s ...
- swoole实现websocket推送
环境配置: swoole 1.9.3.centos6.5(虚拟机).PHP7.01 思路: ①通过server中的collections取出fd ②写一个admin. ...
- swoole创建websocket服务器
目录 1 安装准备 1.1 安装swoole前必须保证系统已经安装了下列软件 1.2 下载并解压 1.3 编译安装成功后,修改php.ini 2 构建Swoole基本实例 2.1 tcp服务器实例 2 ...
- Swoole练习 websocket
WEBSOCKET 服务端代码 //创建websocket服务器对象,监听0.0.0.0:9502端口 $ws = new swoole_websocket_server("0.0.0.0& ...
- swoole websocket服务推送
用过workerman, 两个字"好用",对于swoole最近有时间也研究研究 swoole的websocket 很好实现 如官网 https://wiki.swoole.com/ ...
- PHP - Swoole websocket理解
php swoole实现websocket功能 1.确保安装了swoole扩展. 2.撰写服务程序 <?php //创建websocket服务器对象,监听0.0.0.0:9502端口 $ws = ...
随机推荐
- Mybatis检查SQL注入
Mybatis 的 Mapper.xml 语句中 parameterType 向SQL语句传参有两种方式:#{ } 和 ${ }. 使用#{ }是来防止SQL注入,使用${ }是用来动态拼接参数. 如 ...
- LeetCode-层数最深叶子结点的和
层数最深叶子结点的和 LeetCode-1302 这里可以采用上一题中求解二叉树的深度的方法. 因为需要记录最深结点的值的和,所以这里可以边求和,如果遇到不符合最深结点时再将和sum=0. /** * ...
- Java 开发工具
开发工具·Eclipse 常见开发工具介绍 * A:操作系统自带的记事本软件 * B:高级记事本软件 * C:集成开发环境 IDE * (Integrated Development Envi ...
- roarctf_2019_realloc_magic
目录 roarctf_2019_realloc_magic 总结 题目分析 checksec 函数分析 解题思路 初步解题思路 存在的问题 问题解决方案 最终解决思路 编写exp exp说明 roar ...
- vue项目安装sass步骤等遇到的问题
1.安装sass依赖包 npm install --save-dev sass-loader 注释(可能会出现问题:sass-loader版本过高导致,可以将其package.json中的版本改为7. ...
- Flutter教程- Dart语言规范-知识点整理
Flutter教程- Dart语言知识点整理 Dart语言简介 Dart语言介绍 ① 注释的方式 ② 变量的声明 ③ 字符串的声明和使用 ④ 集合变量的声明 ⑤ 数字的处理 ⑥ 循环的格式 ⑦ 抛异常 ...
- Blind Super-Resolution Kernel Estimation using an Internal-GAN 论文解读
背景与思路来源 目前 SR 模型中合成 LR 使用的模糊核问题 目前大多数 SR 的 model 都是用的合成下采样图片来进行训练的,而这些合成的图片常常使用的是 MATLAB 里面的 imresiz ...
- MyBatis简单的CRUD操作
Dao接口 package com.ttpfx.dao; import com.ttpfx.domain.User; import java.util.List; public interface U ...
- Ubuntu20.04linux内核(5.4.0版本)编译准备与实现过程-编译前准备(1)
最近项目也和linux kernel技术有关,调试内核和内核模块.修改内核源码,是学习内核的重要技术手段之一.应用这些技术时,都有一本基本的要求,那就是编译内核.因此,在分析内核调试技术之前,本随笔给 ...
- greenplum6.14、GPCC6.4安装详解
最近在做gp的升级和整改,所以把做的内容整理下,这篇文章主要是基于gp6.14的安装,主要分为gp,gpcc,pxf的一些安装和初始化.本文为博客园作者所写: 一寸HUI,个人博客地址:https:/ ...