swoft 获取 容器 swoole_http_server 进程worker_id
获取容器123$con = Swoft\Bean\BeanFactory::getContainer();$app = $con->getBeanNames();return var_export($app,true); 通过BeanFactory类可以操作所有的bean通过以上方法可以获取所有的bean名 获取swool_http_server1234$http = Swoft\App::$server;$server = $http->getServer();$pid = $server->worker_pid;return var_export($pid, true);
windows 安装 wsl 跑 swoole swoft
打开wsl控制面板打开linux子系统 安装子系统在cmd里执行bash或者wsl即可,cmd提示需要安装,可以去商店安装,如果把删除了可以执行 1lxrun /install /y 他会自己下载 安装目录1C:\Users\YourName\AppData\Local\lxss\ 安装swoole从官网下载swoole的二进制包,然后执行加压 1tar -Jxf swoole-4.3.0.tar.xz 运行swoft使用完整的目录即可 1/home/bin/php /mnt/c/php/www/swoft/bin/swoft start
swoole 协程异步 带来的性能提升 压力测试
均访问同一cdn数据,模拟访问远程接口的情况 协程异步2009qps同步阻塞432qps协程压测12345678910111213141516171819202122232425262728Concurrency Level: 200Time taken for tests: 0.498 secondsComplete requests: 1000Failed requests: 0Total transferred: 209000 bytesHTML transferred: 19000 bytesRequests per second: 2009.49 [#/sec] (mean)Time per request: 99.528 [ms] (mean)Time per request: 0.498 [ms] (mean, across all concurrent requests)Transfer rate: 410.14 [Kbytes/sec] receive...
thinkphp beego swoft yaf 性能测试 压力测试 php go swoole 速度对比 helloworld
1ab -n 10000 -c 200 测试机为腾讯云1核1G普通云硬盘,如果用ssd的话php成绩会有所提升 输出内容为时间戳 beego swoft的性能都强的不得了,在同一级别,裸跑性能都逼近nginx处理静态文件nginx转发损耗很大,由于nginx转发会导致thinkphp,swoft,beego的性能几乎一样。所以有可能的话还是不要在这些框架外套个nginx了swoft+nginx:内存无波动,CPU占用81%swoft无nginx:内存无波动,CPU占用34% thinkphp+nginx41212345678910111213141516171819202122232425262728Concurrency Level: 200Time taken for tests: 24.256 secondsComplete requests: 10000Failed requests: 0Total transferred: 1940000 bytesHTML transferred: 190000 by...
swoft 开发的坑 路由不生效
自动重载代码失效根据实测,修改文件必须手动重启swoft,自动重载根本没有卵用
golang 导入包
点操作有时候会看到如下的方式导入包 1import( . "fmt" ) 这个点操作的含义就是这个包导入之后在你调用这个包的函数时,你可以省略前缀的包名,也就是前面你调用的fmt.Println(“hello world”) 可以省略的写成Println(“hello world”) 别名操作12import( f "fmt" )f.Println("hello world") _操作说明只是为了执行包中的init函数
thinkphp beego swoft yaf 性能测试 压力测试 php go swoole 速度对比 数据读取
1ab -n 10000 -c 200 统一使用ab在200并发进行10000次请求 为更接近实际使用,用各自模型读取了一条数据 测试机为腾讯云1核1G普通云硬盘,如果用ssd的话php成绩会有所提升 用nginx做转发,会限制golang性能发挥,压测nginx静态页面大概2157qps 首先需要说明,swoft和beego在裸跑时,效率爆棚,几乎逼近处理静态文件,速度是thinkphp的6-7倍.增加nginx后有了较大耗损,差不多是thinkphp的1.7倍.受制于nginx和fpm,yaf这种框架也只是比thinkphp提升了一丢丢,实际意义已经不大 thinkphp+nginx253大部分请求都比较慢,但是基本上是0.8S左右 12345678910111213141516171819202122232425262728Concurrency Level: 200Time taken for tests: 39.601 secondsComplete requests: 10000Failed requests: 0Tota...
golang 类型转换
转换为 字符串如果强制类型转换失败可以使用strconv包 1strconv.FormatBool(bool) 即可将bool转为str
nginx 访问某个目录转发到固定域名并去掉目录名
123456789location /exhibition/ { index index.html index.htm; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://127.0.0.1:8080/; break;} 注意要点1location /exhibition/ 这个后一个斜线要加,否则请求到后端会多一个/ 1proxy_pass http://127.0.0.1:8080/; 这个后一个斜线要加,否则会带上目录名
golang 时间 格式化
go格式化时间必须使用6-1-2-3-4-5这个时间点 时间戳1fmt.Println(time.Now().Unix()) 格式化1fmt.Println(time.Now().Format("2006-01-02 15:04:05")) 时间戳格式化1time.Unix(1389058332, 0).Format("2006-01-02 15:04:05") 时间解析1234the_time, err := time.Parse("2006-01-02 15:04:05", "2014-01-08 09:04:41")if err == nil { unix_time := the_time.Unix()} 其他操作12the_time := time.Date(2014, 1, 7, 5, 50, 4, 0, time.Local)unix_time := the_time.Unix()