php swoole 扩展仿佛为php开发打开了一扇窗户

php workman和swoole原来是两个东东

  • swoole的使用范围更广,能做更多事应该

websocket的介绍

socket 与 websocket也是两个东东

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
}
}

其它参考文档

题外话

  • 今天看了书,看到了一句话,安慰自己:一个人愿意让你爱他,就已经是你很大的幸运了。你得好好爱,别辜负了对方的信任和期待。

最新文章

  1. weblogic 12c web部署注意的问题
  2. Bash基本语法
  3. 自定义泛型N维空间数组
  4. 测试秒杀新版本3.5 stieserver cms
  5. 虚拟化之vmware-网络
  6. try catch 怎么写?
  7. jQuery each,避免使用js for循环
  8. C#-禁止调整窗体的大小
  9. HDU 1157 Who&#39;s in the Middle
  10. node中定时器, process.nextTick(), setImediate()的区别与联系
  11. ASP.NET Core Web 支付功能接入 支付宝-电脑网页支付篇
  12. Python3 的描述符--完整例子详细解释
  13. I - The 3n + 1 problem(2.4.2)
  14. Linux LAMP架构搭建
  15. MySQL 创建自定义函数
  16. Easyui1.3.4+IIS6.0+IE8兼容问题解决
  17. Word Search leetcode java
  18. 【Oracle】Oracle 的过程化SQL(PLSQL)中NULL值的处理
  19. GTID与MHA
  20. 关于分布式存储系统中-CAP原则(CAP定理)与BASE理论比较

热门文章

  1. 后端程序员之路 5、.conf、libconfig
  2. 人脸识别分析小Demo
  3. 靶场练习-Sqli-labs通关记录(1-4关)
  4. 漫漫Java路1—基础知识3—数据类型和变量作用域以及常量
  5. FreeBSD 日常应用
  6. 报错NameError: name ‘null’ is not defined的解决方法
  7. yolo训练数据集
  8. protobuf基于java和javascript的使用
  9. C# yield return 原理探究
  10. Nacos 2.0 正式发布,性能提升 10 倍!!