PHP框架性能測試報告,php框架性能測試_PHP教程
Jul 12, 2016 am 08:53 AMPHP框架性能測試報告,php框架性能測試
作為一個PHP開發(fā)者,而且是初創(chuàng)企業(yè)團隊的技術開發(fā)者,選擇開發(fā)框架是個很艱難的事情。
用ThinkPHP的話,招聘一個剛從培訓機構出來的開發(fā)者就可以上手了,但是性能和后期代碼解耦是個讓人頭疼的事情。不過很多第三方功能不需要自己寫,眾多大牛已經(jīng)給鋪好路了。
用Laravel的話,傳說寫起來很爽擴展性也夠,但是學習成本有點高,總不能給初級開發(fā)者半個月的時間去學習框架吧。而且據(jù)說江湖人士透漏,Laravel性能不怎么樣,文檔也并不是特別豐富。
用Yii的話,語法有點啰嗦,前后端代碼分離有點小麻煩,不過性能是非常好的,而且已經(jīng)有眾多國內大公司在使用了,出現(xiàn)意外可以快速的找到大牛答疑解惑。
不如做個簡單的性能評測,選個性能出色的總不會出錯
性能測試
測試時間: 2016年05月06日
測試工具: siege (因為MAC系統(tǒng)的ab總是會出現(xiàn) pr_socket_recv: Connection reset by peer (54) 的錯誤,所以選擇了siege)
測試機器: MacPro Core i5 處理器/8GB內存/256GB SSD閃存
測試環(huán)境: Apache PHP5.6
框架版本: ThinkPHP 3.2.3 Laravel 5.2 Yii2.0.5
測試原則: 每次測試循環(huán)5次,取中等數(shù)據(jù)
補充說明:所有項目都是讓在子目錄中
結果說明
Transactions: 2119 hits 處理請求總數(shù)量 Availability: 96.85 % 可用性 Elapsed time: 9.74 secs 運行時間 Data transferred: 1.31 MB 數(shù)據(jù)傳輸量 Response time: 0.60 secs 響應時間 Transaction rate: 217.56 trans/sec 每秒處理效率 Throughput: 0.13 MB/sec 每秒處理數(shù)據(jù) Concurrency: 130.28 并發(fā) Successful transactions: 2162 成功的請求 Failed transactions: 69 失敗的請求 Longest transaction: 2.85 最長的單個請求 Shortest transaction: 0.01 最短的單個請求
開始測試
增加一個控制器,并在控制器中輸入10000次HelloWorld
并發(fā)50循環(huán)10次:
首先向我們走來的是ThinkPHP,看上去還行
Transactions: 500 hits Availability: 100.00 % Elapsed time: 2.81 secs Data transferred: 52.45 MB Response time: 0.26 secs Transaction rate: 177.94 trans/sec Throughput: 18.67 MB/sec Concurrency: 47.10 Successful transactions: 500 Failed transactions: 0 Longest transaction: 0.48 Shortest transaction: 0.03
然后是Laravle,嗯,略微有些失望
Transactions: 500 hits Availability: 100.00 % Elapsed time: 13.33 secs Data transferred: 52.45 MB Response time: 1.27 secs Transaction rate: 37.51 trans/sec Throughput: 3.93 MB/sec Concurrency: 47.55 Successful transactions: 500 Failed transactions: 0 Longest transaction: 3.64 Shortest transaction: 0.07
最后賽前比較看好的Yii
Transactions: 500 hits Availability: 100.00 % Elapsed time: 4.84 secs Data transferred: 52.45 MB Response time: 0.46 secs Transaction rate: 103.31 trans/sec Throughput: 10.84 MB/sec Concurrency: 47.65 Successful transactions: 500 Failed transactions: 0 Longest transaction: 0.88 Shortest transaction: 0.04
并發(fā)200循環(huán)10次:
首先是ThinkPHP
Transactions: 1977 hits Availability: 98.85 % Elapsed time: 10.03 secs Data transferred: 207.40 MB Response time: 0.95 secs Transaction rate: 197.11 trans/sec Throughput: 20.68 MB/sec Concurrency: 187.68 Successful transactions: 1977 Failed transactions: 23 Longest transaction: 1.22 Shortest transaction: 0.02
然后是Laravel
Transactions: 1890 hits Availability: 94.50 % Elapsed time: 51.85 secs Data transferred: 198.27 MB Response time: 4.88 secs Transaction rate: 36.45 trans/sec Throughput: 3.82 MB/sec Concurrency: 178.00 Successful transactions: 1890 Failed transactions: 110 Longest transaction: 26.01 Shortest transaction: 0.07
最后是Yii
Transactions: 1996 hits Availability: 99.80 % Elapsed time: 18.95 secs Data transferred: 209.39 MB Response time: 1.79 secs Transaction rate: 105.33 trans/sec Throughput: 11.05 MB/sec Concurrency: 188.57 Successful transactions: 1996 Failed transactions: 4 Longest transaction: 3.29 Shortest transaction: 0.10
沒想到在沒有優(yōu)化的情況下,ThinkPHP的速度是最快的,Yii略微多一些,Laravel步履蹣跚的跑完了測試。結果是有些出人意料的,不過上述的測試只代表了開發(fā)環(huán)境,下面會對框架進行優(yōu)化,模擬線上環(huán)境。
優(yōu)化框架
ThinkPHP:
APP_DEBUG改為false
Laravel:
APP_DEBUG改為false php artisan route:cache php artisan optimize php artisan config:cache composer dumpautoload -o
Yii:
YII_DEBUG改為false
composer dumpautoload -o
并發(fā)200循環(huán)10次:
ThinkPHP
Transactions: 1655 hits Availability: 82.75 % Elapsed time: 8.21 secs Data transferred: 173.62 MB Response time: 0.69 secs Transaction rate: 201.58 trans/sec Throughput: 21.15 MB/sec Concurrency: 139.29 Successful transactions: 1655 Failed transactions: 345 Longest transaction: 7.83 Shortest transaction: 0.00
Laravel:
Transactions: 1520 hits Availability: 76.00 % Elapsed time: 34.95 secs Data transferred: 159.45 MB Response time: 3.15 secs Transaction rate: 43.49 trans/sec Throughput: 4.56 MB/sec Concurrency: 136.84 Successful transactions: 1520 Failed transactions: 480 Longest transaction: 19.18 Shortest transaction: 0.00
Yii:
Transactions: 1704 hits Availability: 85.20 % Elapsed time: 15.16 secs Data transferred: 178.76 MB Response time: 1.46 secs Transaction rate: 112.40 trans/sec Throughput: 11.79 MB/sec Concurrency: 164.21 Successful transactions: 1704 Failed transactions: 296 Longest transaction: 9.04 Shortest transaction: 0.00
比較奇怪的一點,當框架關掉調試模式后都出現(xiàn)了較多失敗的情況。不過明顯的看到,Laravel進行簡單的優(yōu)化后,性能大大的提升了,但還是低于其他兩個框架。
結論
在測試的過程中,其他我的心情是沮喪的,感覺自己的三觀世界已經(jīng)崩塌了,崩塌至渣。
ThinkPHP的性能比Yii高出一倍,比Laravel高出近四倍
Yii的性能比較中庸,但是在測試中會明顯發(fā)現(xiàn)請求失敗的情況比其他兩個框架要少
Laravel依舊優(yōu)雅,不過性能堪憂,用網(wǎng)友的話形容比較好 學之者生用之者死
最后
我的項目最后使用了自建框架進行開發(fā),得益于composer的強大,開發(fā)的過程非常順利,最后附上自有框架在200并發(fā)10次循環(huán)的數(shù)據(jù),框架開源但是更新比較忙,歡迎在github上搜索PPPHP,和我一起搭建框架。
Transactions: 1672 hits Availability: 83.60 % Elapsed time: 6.18 secs Data transferred: 175.40 MB Response time: 0.57 secs Transaction rate: 270.55 trans/sec Throughput: 28.38 MB/sec Concurrency: 153.16 Successful transactions: 1672 Failed transactions: 328 Longest transaction: 4.57 Shortest transaction: 0.01

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











PHP ??? ??????? ?? ??? ??? ??? ??? ?? ??? ?? ??? ????. ??? ?? ?????. 1. ?? PHP ?? ? ???? ??? ???? ?? ? ?? phpinfo.php ??? ???? ? ? ????. 2. ??? ? ??? ???? ??????. 8.2 ?? 8.1? ???? ?? ????. Linux ???? Package Manager? ???? MacOS ???? Homebrew? ?????. 3. ?? ?? ? ???? ???????? php.ini? ?????? ??? ??? ??????. 4. ? ???? ????? ?? ??? ????? ?? ??? ???? ??? ??? ??? ??????. ?? ??? ??? ???? ???? ?????? ????? ?? ? ? ????.

TopreventCSRFattacksinPHP,implementanti-CSRFtokens.1)Generateandstoresecuretokensusingrandom_bytes()orbin2hex(random_bytes(32)),savethemin$_SESSION,andincludetheminformsashiddeninputs.2)ValidatetokensonsubmissionbystrictlycomparingthePOSTtokenwiththe

PHP ?? ??? ????? ??? ??? ???? ??? ???? ???????. ?? ???? PHP ?? ???? ? ?? ?? ??? ?????. ? ?? (Apache ?? Nginx), PHP ?? ? ?????? (? : MySQL/MariaDB); ???? XAMPP ?? MAMP? ?? ?? ???? ???? ?? ????? ????? ?? ????. XAMPP? Windows ? MacOS? ?????. ?? ? ???? ??? HTDOCS ????? ???? LocalHost? ?? ??????. mAMP? MAC ????? ???? PHP ??? ??? ??? ????? ?? ???? ??? ???? ????. ④ ?? ???? MacOS/Linux ????? Homebrew? ???? ??? ? ????.

? ?? PHP ??? ???? ?? ? ?? ????? ? ?? ?? ??? ????. 1. ??? ??? ?? ?? ??? ?? Array_Merge ? Array_unique ??? ??????. ?? Array_Merge ($ array1, $ array2)? ?? ? ?? Array_Unique ()? ???? ?? ?? ? ?? ???? ? ??? ?????. 2. ?? ?? ? ? ?? ???? ? ? ?? ????? ???? ??????. $ result = $ array1 $ array2? ? ?? ??? ?? ? ?? ??? ?? ?? ?? ??????. ? ? ?? ??? ? ??? ????? ??? ?? ?

EXIT ()? ???? ??? ?? ???? ? ???? PHP? ?????. ???? ???? ??? ?????. 1. ??? ???? ??? ??? ???? ?? ?? ??? ?? ? ? ????? ?? ?????. 2. ??? ? ?? ?? ?? ? ?? ??; 3. ?? ?? ??? ???? ?? Header ()? ?? ???? ? Exit ()? ??????. ?? exit ()? ??? ?? ??? ?? ??? ?? ??? ?? ??? ?? ? ? ??? ??? ?? ()???.

HTML?? ??? ??? ????? ???? ??? ?? ???, ??? ? SEO ??? ?? ? ? ????. 1. ??? ????? ??? ?? ??? ? ??? ??? ????? ?? ????????. 2. ????? ??? ???? ?? ?? ???? ???? ???? ?? ??? ?????. 3. ? ???? ??? ?? ??? ????? ??? ? ?? ?? ?? ?? ????? ?? ??? ????. ?? ???? ??? ??????? ?? ??? ??? ??? ???? ???? ??? ??? ?? ??? ???? ???????.

PHP? ?? ???? ?????? ?? ??? ??? ?? $ _session hyperglobal ???? ?? ???????. 1. ??? session_start ()? ???? ??????, ?? ?? ??? ???????. 2. ?? ???? ??? ? ? ?? ????? ??????. ISSET ($ _ session [ 'key']) ?? array_key_exists ( 'key', $ _ session)? ??? ? ????. 3. ?? ??? ????? ????????. ?? ???? $ _session ??? ?? ???????. 4. UNSET ($ _ session [ 'key'])? ?? ???? ??? ?? ???? ??? $ _session? ? ??? ??????.

?? ??? PHP? ?? ? ??? ?????. ?? ??? 1???. ?? ??? ???? (?? ?), 2. ??? ???? ?? ??? ???? (?? ?). ?? ? ??? ????, ?? ?? ??? ?????, ?? ?? ??, ???? ???? ?? ?? ?? ??? ??? ?????, ??? ?? ? ?? ?? ???? ?????? ???????. ?? ?? ?? ??? ??????? ?? ??? ?? ?????? ?? ?? ??? ????? ?? ??? ????????. ?? ??, ????? ?? ? ? ??? ?? ????? ???? ?? ??? ?? ? ??? ?? ??? ?????.
