swoole statistic
是一个可以监控API访问频率、耗时、成功率的系统。
传送门 —> https://github.com/toxmc/statistics
准备:
Swoole php容器 (使用的是官方的源)
Nginx容器
在宿主机项目目录中运行以下命令 拉取swoole statistic项目 (宿主机该目录已经挂载到swoole php容器中 属于基础入门知识,查看博客docker栏目或者百度~)
git clone
git@github.com:toxmc/statistics.git statistics
进入该目录中
cd statistics
启动运行
php web.php
php worker.php
接着需要配置nginx虚拟主机 绑定域名 swoole statistic项目中已经带有conf文件 (Readme.md也有简易步骤说明)
在nginx.conf
中加上以下内容
upstream swoole_statistics {
// 这是项目原来文件的写法 不能这样子写 server 127.0.0.1:6666; #swoole_http_server
server 172.17.0.2:6666; // 要这样子写 172.17.0.2是你的swoole php容器的容器ip 关于如何查看该ip可以百度 docker 查看容器ip
}
## Start tongji.val.xyz ##
server {
listen 80;
server_name statistics.xxx.com; // 这里是你的域名
root /Users/xmc/PhpstormProjects/statistics/Web;
index index.html index.htm index.php;
## send request back to swoole_http_server ##
location / {
#proxy_pass http://127.0.0.1:6666;
proxy_pass http://swoole_statistics;
#Proxy Settings
proxy_redirect off;
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js|css|ico)$
{
access_log off;
expires 0d;
}
}
重启nginx容器
docker restart nginx(你nginx容器的名字)
访问刚刚绑定的域名 即可看到web后台 登录,配置数据源 填入0.0.0.0
接着把 swoole statistic项目中Example
文件夹复制到其他的域名下,然后访问 xxx.com/clinet.php
模拟推送api访问结果。
即可在swoole statistic后台中看到统计~
最后推荐大家可以用下我开源的一个基于Swoole4.5+研发的PHP框架。该框架基于注解实现了很多好玩的功能,很适合新人快速上手Swoole扩展。
SW-X框架-专注高性能便捷开发而生的PHP-SwooleX框架www.sw-x.cn