Table of Contents
主流PHP框架性能非权威测试
性能测试
结果说明
开始测试
增加一个控制器,并在控制器中输入10000次HelloWorld
优化框架
结论
最后
Home Backend Development PHP Tutorial 主流PHP框架性能非权威测试

主流PHP框架性能非权威测试

Jun 20, 2016 pm 12:29 PM

主流PHP框架性能非权威测试

作为一个PHP开发者,而且是初创企业团队的技术开发者,选择开发框架是个很艰难的事情。

用 ThinkPHP的话,招聘一个刚从培训机构出来的开发者就可以上手了,但是性能和后期代码解耦是个让人头疼的事情。不过很多第三方功能不需要自己写,众多大牛已经给铺好路了。

用 Laravel的话,传说写起来很爽扩展性也够,但是学习成本有点高,总不能给初级开发者半个月的时间去学习框架吧。而且据说江湖人士透漏, Laravel性能不怎么样,文档也并不是特别丰富。

用 Yii的话,语法有点啰嗦,前后端代码分离有点小麻烦,不过性能是非常好的,而且已经有众多国内大公司在使用了,出现意外可以快速的找到大牛答疑解惑。

不如做个简单的性能评测,选个性能出色的总不会出错

性能测试

  • 测试时间: 2016年05月06日

  • 测试工具: siege(因为MAC系统的 ab总是会出现 pr_socket_recv: Connection reset by peer (54)的错误,所以选择了 siege)

  • 测试机器: MacPro Core i5 处理器/8GB内存/256GB SSD闪存

  • 测试环境: Apache PHP5.6

  • 框架版本: ThinkPHP 3.2.3 Laravel 5.2 Yii2.0.5

  • 测试原则: 每次测试循环5次,取中等数据

补充说明:所有项目都是让在子目录中

结果说明

Transactions:                2119 hits  处理请求总数量Availability:               96.85 %  可用性Elapsed time:                9.74 secs  运行时间Data transferred:            1.31 MB 数据传输量Response time:                0.60 secs 响应时间Transaction rate:          217.56 trans/sec 每秒处理效率Throughput:                0.13 MB/sec 每秒处理数据Concurrency:              130.28 并发Successful transactions:        2162 成功的请求Failed transactions:              69 失败的请求Longest transaction:            2.85 最长的单个请求Shortest transaction:            0.01 最短的单个请求
Copy after login

开始测试

增加一个控制器,并在控制器中输入10000次HelloWorld

并发50循环10次:

首先向我们走来的是ThinkPHP,看上去还行

Transactions:                 500 hitsAvailability:              100.00 %Elapsed time:                2.81 secsData transferred:           52.45 MBResponse time:                0.26 secsTransaction rate:          177.94 trans/secThroughput:               18.67 MB/secConcurrency:               47.10Successful transactions:         500Failed transactions:               0Longest transaction:            0.48Shortest transaction:            0.03
Copy after login

然后是Laravle,嗯,略微有些失望

Transactions:                 500 hitsAvailability:              100.00 %Elapsed time:               13.33 secsData transferred:           52.45 MBResponse time:                1.27 secsTransaction rate:           37.51 trans/secThroughput:                3.93 MB/secConcurrency:               47.55Successful transactions:         500Failed transactions:               0Longest transaction:            3.64Shortest transaction:            0.07
Copy after login

最后赛前比较看好的Yii

Transactions:                 500 hitsAvailability:              100.00 %Elapsed time:                4.84 secsData transferred:           52.45 MBResponse time:                0.46 secsTransaction rate:          103.31 trans/secThroughput:               10.84 MB/secConcurrency:               47.65Successful transactions:         500Failed transactions:               0Longest transaction:            0.88Shortest transaction:            0.04
Copy after login

并发200循环10次:

首先是ThinkPHP

Transactions:                1977 hitsAvailability:               98.85 %Elapsed time:               10.03 secsData transferred:          207.40 MBResponse time:                0.95 secsTransaction rate:          197.11 trans/secThroughput:               20.68 MB/secConcurrency:              187.68Successful transactions:        1977Failed transactions:              23Longest transaction:            1.22Shortest transaction:            0.02
Copy after login

然后是Laravel

Transactions:                1890 hitsAvailability:               94.50 %Elapsed time:               51.85 secsData transferred:          198.27 MBResponse time:                4.88 secsTransaction rate:           36.45 trans/secThroughput:                3.82 MB/secConcurrency:              178.00Successful transactions:        1890Failed transactions:             110Longest transaction:           26.01Shortest transaction:            0.07
Copy after login

最后是Yii

Transactions:                1996 hitsAvailability:               99.80 %Elapsed time:               18.95 secsData transferred:          209.39 MBResponse time:                1.79 secsTransaction rate:          105.33 trans/secThroughput:               11.05 MB/secConcurrency:              188.57Successful transactions:        1996Failed transactions:               4Longest transaction:            3.29Shortest transaction:            0.10
Copy after login

没想到在没有优化的情况下,ThinkPHP的速度是最快的,Yii略微多一些,Laravel步履蹒跚的跑完了测试。结果是有些出人意料的,不过上述的测试只代表了开发环境,下面会对框架进行优化,模拟线上环境。

优化框架

ThinkPHP:

APP_DEBUG改为true
Copy after login

Laravel:

APP_DEBUG改为falsephp artisan route:cachephp artisan optimizephp artisan config:cachecomposer dumpautoload -o
Copy after login

Yii:

YII_DEBUG改为falsecomposer dumpautoload -o
Copy after login

并发200循环10次:

ThinkPHP

Transactions:                1655 hitsAvailability:               82.75 %Elapsed time:                8.21 secsData transferred:          173.62 MBResponse time:                0.69 secsTransaction rate:          201.58 trans/secThroughput:               21.15 MB/secConcurrency:              139.29Successful transactions:        1655Failed transactions:             345Longest transaction:            7.83Shortest transaction:            0.00
Copy after login

Laravel:

Transactions:                1520 hitsAvailability:               76.00 %Elapsed time:               34.95 secsData transferred:          159.45 MBResponse time:                3.15 secsTransaction rate:           43.49 trans/secThroughput:                4.56 MB/secConcurrency:              136.84Successful transactions:        1520Failed transactions:             480Longest transaction:           19.18Shortest transaction:            0.00
Copy after login

Yii:

Transactions:                1704 hitsAvailability:               85.20 %Elapsed time:               15.16 secsData transferred:          178.76 MBResponse time:                1.46 secsTransaction rate:          112.40 trans/secThroughput:               11.79 MB/secConcurrency:              164.21Successful transactions:        1704Failed transactions:             296Longest transaction:            9.04Shortest transaction:            0.00
Copy after login

比较奇怪的一点,当框架关掉调试模式后都出现了较多失败的情况。不过明显的看到,Laravel进行简单的优化后,性能大大的提升了,但还是低于其他两个框架。

结论

在测试的过程中,其他我的心情是沮丧的,感觉自己的三观世界已经崩塌了,崩塌至渣。

  • ThinkPHP的性能比Yii高出一倍,比Laravel高出近四倍

  • Yii的性能比较中庸,但是在测试中会明显发现请求失败的情况比其他两个框架要少

  • Laravel依旧优雅,不过性能堪忧,用网友的话形容比较好 学之者生用之者死

最后

我的项目最后使用了自建框架进行开发,得益于composer的强大,开发的过程非常顺利,最后附上自有框架在200并发10次循环的数据,框架开源但是更新比较忙,欢迎在github上搜索PPPHP,和我一起搭建框架。

Transactions:                1672 hitsAvailability:               83.60 %Elapsed time:                6.18 secsData transferred:          175.40 MBResponse time:                0.57 secsTransaction rate:          270.55 trans/secThroughput:               28.38 MB/secConcurrency:              153.16Successful transactions:        1672Failed transactions:             328Longest transaction:            4.57Shortest transaction:            0.01
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

See all articles