Phalcon 和 Laravel 的效率还是差很多的。
2016-07-21一直很喜欢Laravel的项目结构设计,很喜欢它和rails的控制台工具。但是项目中一直在用Phalcon,无他,简单、熟悉了。而且,性能上确实非常非常好!
看了很多评测的,今天抽空自己做了一点点测试,看的结果更加直观:
环境:Mac、PHP7.0.8、Phalcon 2.1.0RC、Larave 5.2.40
程序:
Laravel使用默认环境,创建一个Index控制器,一个index方法,显示一行文字。使用optimize优化了。
Phalcon由于没有使用脚手架工具创建项目,自己手工搭建一下,主要就是创建路由、定义视图、挂载模板引擎(volt),将这些注入到di中,同样一个控制器,一个方法,显示同样的模板。
测试:ab -c 10 -n 1000 http://pails.xueron.com/ ,其中c是并发,n是请求总次数。调整两个参数,反复测试。
结果:
基本上laravel的rps(Requests per second)一直在25~40之间。一般为30多点。
而Phalcon的rps基本保持在500+,在500~650之间。
差太多啊~
虚伪的灵魂 做了比较详细的测试:http://xwsoul.com/posts/1071,可以看到,效率主要差在stat/lstat/open/access这些文件的查找与打开上面了。看过Laravel的源码,在依赖注入的设计上面很精巧,但是也带来的问题,就是加载、反射、反复查找~, 效率牺牲的可不是一点半点。
所以打算做个小项目,就是为Phalcon弄一个简单的架子,什么di的服务、配置等等弄弄好,这样用phalcon建项目easy一点……
测试结果:
php-fpm运行larave的情况,可以看到时间耗用和CPU的占用都挺大:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
[www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=195.914 Mem=2048 Cpu=U:40.83%;S:5.10%;T:45.94% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=210.408 Mem=2048 Cpu=U:38.02%;S:4.75%;T:42.77% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=207.224 Mem=2048 Cpu=U:38.61%;S:4.83%;T:43.43% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=197.408 Mem=2048 Cpu=U:45.59%;S:5.07%;T:50.66% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=197.402 Mem=2048 Cpu=U:40.53%;S:5.07%;T:45.59% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=187.554 Mem=2048 Cpu=U:42.65%;S:5.33%;T:47.99% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=181.838 Mem=2048 Cpu=U:44.00%;S:5.50%;T:49.49% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=204.391 Mem=2048 Cpu=U:44.03%;S:9.79%;T:53.82% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=198.261 Mem=2048 Cpu=U:40.35%;S:10.09%;T:50.44% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=213.622 Mem=2048 Cpu=U:42.13%;S:4.68%;T:46.81% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=197.825 Mem=2048 Cpu=U:45.49%;S:10.11%;T:55.60% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=202.137 Mem=2048 Cpu=U:39.58%;S:9.89%;T:49.47% [www] 127.0.0.1 - 21/Jul/2016:14:17:30 +0800 "GET /index.php" 200 .... Time=221.151 Mem=2048 Cpu=U:36.17%;S:4.52%;T:40.70% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=168.815 Mem=2048 Cpu=U:53.31%;S:5.92%;T:59.24% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=168.277 Mem=2048 Cpu=U:47.54%;S:5.94%;T:53.48% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=184.290 Mem=2048 Cpu=U:48.84%;S:5.43%;T:54.26% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=166.918 Mem=2048 Cpu=U:47.93%;S:5.99%;T:53.92% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=159.977 Mem=2048 Cpu=U:50.01%;S:12.50%;T:62.51% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=209.724 Mem=2048 Cpu=U:42.91%;S:9.54%;T:52.45% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=186.367 Mem=2048 Cpu=U:42.93%;S:5.37%;T:48.29% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=171.344 Mem=2048 Cpu=U:40.85%;S:5.84%;T:46.69% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=195.746 Mem=2048 Cpu=U:45.98%;S:10.22%;T:56.20% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=179.811 Mem=2048 Cpu=U:44.49%;S:5.56%;T:50.05% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=159.584 Mem=2048 Cpu=U:50.13%;S:6.27%;T:56.40% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=141.376 Mem=2048 Cpu=U:56.59%;S:7.07%;T:63.66% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=152.181 Mem=2048 Cpu=U:52.57%;S:13.14%;T:65.71% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=148.747 Mem=2048 Cpu=U:53.78%;S:6.72%;T:60.51% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=188.122 Mem=2048 Cpu=U:42.53%;S:10.63%;T:53.16% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=222.400 Mem=2048 Cpu=U:35.97%;S:4.50%;T:40.47% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=234.064 Mem=2048 Cpu=U:34.18%;S:4.27%;T:38.45% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=223.316 Mem=2048 Cpu=U:35.82%;S:4.48%;T:40.30% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=204.123 Mem=2048 Cpu=U:44.09%;S:4.90%;T:48.99% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=185.770 Mem=2048 Cpu=U:48.45%;S:10.77%;T:59.21% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=178.269 Mem=2048 Cpu=U:44.88%;S:5.61%;T:50.49% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=181.095 Mem=2048 Cpu=U:49.70%;S:5.52%;T:55.22% [www] 127.0.0.1 - 21/Jul/2016:14:17:31 +0800 "GET /index.php" 200 .... Time=151.841 Mem=2048 Cpu=U:52.69%;S:13.17%;T:65.86% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=169.613 Mem=2048 Cpu=U:47.17%;S:5.90%;T:53.06% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=150.290 Mem=2048 Cpu=U:46.58%;S:13.31%;T:59.88% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=166.815 Mem=2048 Cpu=U:47.96%;S:5.99%;T:53.95% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=136.843 Mem=2048 Cpu=U:58.46%;S:7.31%;T:65.77% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=152.656 Mem=2048 Cpu=U:52.41%;S:6.55%;T:58.96% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=159.144 Mem=2048 Cpu=U:50.27%;S:6.28%;T:56.55% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=143.945 Mem=2048 Cpu=U:55.58%;S:6.95%;T:62.52% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=134.992 Mem=2048 Cpu=U:59.26%;S:7.41%;T:66.67% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=152.695 Mem=2048 Cpu=U:52.39%;S:13.10%;T:65.49% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=165.980 Mem=2048 Cpu=U:48.20%;S:6.02%;T:54.22% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=171.853 Mem=2048 Cpu=U:46.55%;S:11.64%;T:58.19% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=168.789 Mem=2048 Cpu=U:53.32%;S:5.92%;T:59.25% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=180.222 Mem=2048 Cpu=U:44.39%;S:5.55%;T:49.94% [www] 127.0.0.1 - 21/Jul/2016:14:17:32 +0800 "GET /index.php" 200 .... Time=182.382 Mem=2048 Cpu=U:43.86%;S:5.48%;T:49.35% |
ab测试结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
Server Software: nginx Server Hostname: laravel.local.com Server Port: 80 Document Path: / Document Length: 931 bytes Concurrency Level: 10 Time taken for tests: 27.875 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 1925992 bytes HTML transferred: 931000 bytes Requests per second: 35.87 [#/sec] (mean) Time per request: 278.749 [ms] (mean) Time per request: 27.875 [ms] (mean, across all concurrent requests) Transfer rate: 67.47 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 2 Processing: 132 278 135.5 243 1567 Waiting: 132 277 135.5 243 1567 Total: 132 278 135.5 243 1568 Percentage of the requests served within a certain time (ms) 50% 243 66% 262 75% 282 80% 293 90% 335 95% 403 98% 923 99% 1025 100% 1568 (longest request) |
下面是Phalcon的情况,好很多:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
[www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=4.111 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.479 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.865 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.603 Mem=2048 Cpu=U:384.17%;S:384.17%;T:768.34% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.067 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=8.258 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.115 Mem=2048 Cpu=U:472.81%;S:0.00%;T:472.81% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.189 Mem=2048 Cpu=U:0.00%;S:313.58%;T:313.58% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.294 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.292 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.368 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.529 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.221 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.906 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.189 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=33.383 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.497 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.297 Mem=2048 Cpu=U:303.31%;S:0.00%;T:303.31% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.331 Mem=2048 Cpu=U:429.00%;S:0.00%;T:429.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.449 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.523 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.122 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.195 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.485 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.301 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=7.716 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.246 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.277 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.305 Mem=2048 Cpu=U:433.84%;S:0.00%;T:433.84% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.765 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.710 Mem=2048 Cpu=U:369.00%;S:0.00%;T:369.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.351 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.089 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.865 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.790 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=8.027 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.194 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.403 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.082 Mem=2048 Cpu=U:480.31%;S:0.00%;T:480.31% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=6.163 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.388 Mem=2048 Cpu=U:418.76%;S:0.00%;T:418.76% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.055 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=3.302 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.130 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.650 Mem=2048 Cpu=U:377.36%;S:0.00%;T:377.36% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.067 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=4.741 Mem=2048 Cpu=U:210.93%;S:210.93%;T:421.85% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.180 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.362 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% [www] 127.0.0.1 - 21/Jul/2016:14:43:19 +0800 "GET /index.php" 200 .... Time=2.348 Mem=2048 Cpu=U:0.00%;S:0.00%;T:0.00% |
ab测试的结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
Server Software: nginx Server Hostname: phalcon.local.com Server Port: 80 Document Path: / Document Length: 775 bytes Concurrency Level: 10 Time taken for tests: 1.555 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 953000 bytes HTML transferred: 775000 bytes Requests per second: 642.89 [#/sec] (mean) Time per request: 15.555 [ms] (mean) Time per request: 1.555 [ms] (mean, across all concurrent requests) Transfer rate: 598.32 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.5 0 7 Processing: 7 15 6.7 13 66 Waiting: 7 15 6.6 13 66 Total: 7 15 6.6 13 66 Percentage of the requests served within a certain time (ms) 50% 13 66% 15 75% 17 80% 19 90% 22 95% 27 98% 35 99% 45 100% 66 (longest request) |
好久不更新了,动弹一下……
2016-03-16使用Docker,PHP7,重新构建了一下本站,速度提高没提高不知道……
下一步,使用PHP7+Phalcon(2.1.x)……
下一步,使用Ruby……
下一步,产品……
PhalconPHP and PHP7
2016-03-16From: http://phalcon.io/phalconphp-and-php7
PHP7 was released on the 3rd of December, 2015. This new version brought forward a large number of new and exiting features (http://php.net/manual/en/migration70.new-features.php) to PHP. Perhaps one of the biggest of the new features is a new Zend Engine (the engine that powers PHP).
This new engine, code named PHPNG, will give some of your applications double the performance speed.
Some benchmarks that have been run so far:
WordPress 3.6 – 20.0% gain (253 vs 211 req/sec)
Drupal 6.1 – 11.7% gain (1770 vs 1585 req/sec)
Qdig – 15.3% gain (555 vs 482 req/sec)
ZF test app – 30.5% gain (217 vs 166 req/sec)
It is only natural that once it came out the PhalconPHP community was dying to know when we would get a chance to work with PhalconPHP and PHP7.
The Problem
We all know that PhalconPHP is written in Zephir starting with version 2.0, and that this language compiles its code into a C PHP Extension. Because of PHP7’s new engine the extension had to be rewritten and adapted to the new specifications.
The Solution
Knowing this, the PhalconPHP team started working since last year on an updated version of Zephir to make the compiled code work with PHP7.
After a few months we are finally delivered PhalconPHP 2.1 and Zephir 0.9.x which brings PHP7 support.
Installing PhalconPHP with PHP7
You will need to install PHP7+ and Zephir 0.9.2a-dev (or its latest branch). After you have them installed go to PhalconPHP 2.1.0+ branch and download the source code.
Installation example:
1 2 |
root@localhost:~$ cd cphalcon-2.1.x/ root@localhost:~/cphalcon-2.1.x$ zephir build —backend=ZendEngine3 |
If you get these warnings ignore them:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Warning: Variable "_SESSION" assigned but not used in Phalcon\Session\Adapter::remove in /root/cphalcon-2.1.x/phalcon/session/adapter.zep on 204 [unused-variable] } -^ Warning: Variable "beforeLine" assigned but not used in Phalcon\Debug::showTraceItem in /root/cphalcon-2.1.x/phalcon/debug.zep on 339 [unused-variable] beforeLine, firstLine, afterLine, lastLine, i, linePosition, currentLine; -------------^ Warning: Variable "possibleSetter" declared but not used in Phalcon\Mvc\Model::assign in /root/cphalcon-2.1.x/phalcon/mvc/model.zep on 440 [unused-variable] var key, keyMapped, value, attribute, attributeField, possibleSetter, metaData, columnMap, dataMapped; ----------------------------------------------------------------------^ Warning: Function "\\sodium\\randombytes_buf" does not exist at compile time in /root/cphalcon-2.1.x/phalcon/security/random.zep on 119 [nonexistent-function] return \\Sodium\\randombytes_buf(len); ----------------------------------------^ Warning: Function "\\sodium\\randombytes_uniform" does not exist at compile time in /root/cphalcon-2.1.x/phalcon/security/random.zep on 310 [nonexistent-function] return \\Sodium\\randombytes_uniform(len); --------------------------------------------^ Compiling... Installing... Extension installed! Don't forget to restart your web server root@localhost:~/cphalcon-2.1.x$ service php-fpm restart |
That’s it!
You now have PhalconPHP and PHP7 working.
Can you expect PhalconPHP to be even faster? No, but you can expect to see your your app be much faster since your PHP code will run better with the new engine. Plus, you won’t have any overhead since PhalconPHP is a extension. The best part of all this is that you get all the new features that PHP7 brings to the table.
Do take into account that PHP7 is still rather new, and most of the commonly used extensions like memcache, memcached, and redis are available in Dev/Beta branches, so you need to reinstall them.
Best of luck to all and enjoy PhalconPHP + PHP7.
Phalcon 连接数据库中文字符集的问题
2014-08-11网上的方法都是在配置里面添加charset,结果我苦逼的调试了好一会。
后来才发现我的php版本是5.3.3的,这样是不行滴!
5.3.6 Prior to version 5.3.6, charset was ignored.
1 2 3 4 5 6 7 8 9 10 11 12 |
$di['db'] = function () use ($config) { $conn = new DbAdapter(array( "host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "charset" => 'utf8', // 在php 5.3.6之前无效 )); $conn->query("set names utf8");// 变通解决办法 return $conn; }; |
PHP网站改版了,5.3.x要结束了。。。
2013-07-12
坑爹的百度啊!
2012-10-27今天写PHP,偶遇一个错误:called without object from outside a class ,于是百度查看一下详情,结果,度娘将所有网站报这个错误的都给我抓回来了。
看人家google,就知道俺想找啥么。