


PHP framework performance test report, php framework performance test_PHP tutorial
Jul 12, 2016 am 08:53 AMPHP framework performance test report, php framework performance test
As a PHP developer and a technical developer of a start-up team, choosing a development framework is a very difficult thing.
With ThinkPHP, you can get started by recruiting a developer who has just graduated from a training institution, but decoupling performance from post-code is a headache. However, many third-party functions do not need to be written by yourself, as many experts have already paved the way.
With Laravel, Legend is very comfortable to write and has sufficient scalability, but the learning cost is a bit high. You can’t give junior developers half a month to learn the framework. And it is said that people in the world have revealed that Laravel’s performance is not very good, and the documentation is not particularly rich.
With Yii, the syntax is a bit cumbersome, and the separation of front-end and back-end code is a little troublesome, but the performance is very good, and it is already used by many large domestic companies. If something unexpected happens, you can quickly find an expert to answer your questions.
It’s better to do a simple performance evaluation. You can’t go wrong by choosing one with excellent performance
Performance Test
Testing time: May 6, 2016
Test tool: siege (because the ab of MAC system always has the error pr_socket_recv: Connection reset by peer (54), so I chose siege)
Test machine: MacPro Core i5 processor/8GB memory/256GB SSD flash memory
Test environment: Apache PHP5.6
Framework version: ThinkPHP 3.2.3 Laravel 5.2 Yii2.0.5
Testing principle: Each test cycle is 5 times, and medium data is taken
Additional note: All projects are placed in subdirectories
Explanation of results
Transactions: 2119 hits 處理請求總數(shù)量 Availability: 96.85 % 可用性 Elapsed time: 9.74 secs 運(yùn)行時(shí)間 Data transferred: 1.31 MB 數(shù)據(jù)傳輸量 Response time: 0.60 secs 響應(yīng)時(shí)間 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 最長的單個(gè)請求 Shortest transaction: 0.01 最短的單個(gè)請求
Start testing
Add a controller and enter HelloWorld 10,000 times in the controller
Concurrency 50 loops 10 times:
The first thing that came to us was ThinkPHP, which looked okay
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
Then Laravle, well, slightly disappointed
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, who was relatively optimistic before the final game
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
Concurrency 200 loops 10 times:
First is 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
Then 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
Finally 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
Unexpectedly, without optimization, ThinkPHP was the fastest, Yii was slightly faster, and Laravel finished the test at a faltering pace. The results are somewhat unexpected, but the above test only represents the development environment. The framework will be optimized below to simulate the online environment.
Optimization framework
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 changed to false
composer dumpautoload -o
Concurrency 200 loop 10 times:
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
The strange thing is that when the framework turns off the debugging mode, there are more failures. However, it is obvious that after simple optimization, Laravel's performance has been greatly improved, but it is still lower than the other two frameworks.
Conclusion
During the test, I felt depressed and felt that my world view had collapsed, to the point of collapse.
ThinkPHP’s performance is twice as high as Yii and nearly four times higher than Laravel
The performance of Yii is relatively mediocre, but in the test, it is obvious that there are fewer request failures than the other two frameworks
Laravel is still elegant, but its performance is worrying. It is better to describe it in the words of netizens: Those who learn will live, those who use it will die
Finally
My project ended up using a self-built framework for development. Thanks to the power of composer, the development process went very smoothly. Finally, I attached the data of the self-built framework running 200 concurrent cycles for 10 times. The framework is open source but the update is quite busy. Welcome to search PPPHP on github and build the framework with me.
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

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Upgrading the PHP version is actually not difficult, but the key lies in the operation steps and precautions. The following are the specific methods: 1. Confirm the current PHP version and running environment, use the command line or phpinfo.php file to view; 2. Select the suitable new version and install it. It is recommended to install it with 8.2 or 8.1. Linux users use package manager, and macOS users use Homebrew; 3. Migrate configuration files and extensions, update php.ini and install necessary extensions; 4. Test whether the website is running normally, check the error log to ensure that there is no compatibility problem. Follow these steps and you can successfully complete the upgrade in most situations.

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

To set up a PHP development environment, you need to select the appropriate tools and install the configuration correctly. ①The most basic PHP local environment requires three components: the web server (Apache or Nginx), the PHP itself and the database (such as MySQL/MariaDB); ② It is recommended that beginners use integration packages such as XAMPP or MAMP, which simplify the installation process. XAMPP is suitable for Windows and macOS. After installation, the project files are placed in the htdocs directory and accessed through localhost; ③MAMP is suitable for Mac users and supports convenient switching of PHP versions, but the free version has limited functions; ④ Advanced users can manually install them by Homebrew, in macOS/Linux systems

To merge two PHP arrays and keep unique values, there are two main methods. 1. For index arrays or only deduplication, use array_merge and array_unique combinations: first merge array_merge($array1,$array2) and then use array_unique() to deduplicate them to finally get a new array containing all unique values; 2. For associative arrays and want to retain key-value pairs in the first array, use the operator: $result=$array1 $array2, which will ensure that the keys in the first array will not be overwritten by the second array. These two methods are applicable to different scenarios, depending on whether the key name is retained or only the focus is on

exit() is a function in PHP that is used to terminate script execution immediately. Common uses include: 1. Terminate the script in advance when an exception is detected, such as the file does not exist or verification fails; 2. Output intermediate results during debugging and stop execution; 3. Call exit() after redirecting in conjunction with header() to prevent subsequent code execution; In addition, exit() can accept string parameters as output content or integers as status code, and its alias is die().

The rational use of semantic tags in HTML can improve page structure clarity, accessibility and SEO effects. 1. Used for independent content blocks, such as blog posts or comments, it must be self-contained; 2. Used for classification related content, usually including titles, and is suitable for different modules of the page; 3. Used for auxiliary information related to the main content but not core, such as sidebar recommendations or author profiles. In actual development, labels should be combined and other, avoid excessive nesting, keep the structure simple, and verify the rationality of the structure through developer tools.

To access session data in PHP, you must first start the session and then operate through the $_SESSION hyperglobal array. 1. The session must be started using session_start(), and the function must be called before any output; 2. When accessing session data, check whether the key exists. You can use isset($_SESSION['key']) or array_key_exists('key',$_SESSION); 3. Set or update session variables only need to assign values ??to the $_SESSION array without manually saving; 4. Clear specific data with unset($_SESSION['key']), clear all data and set $_SESSION to an empty array.

Recursive functions refer to self-call functions in PHP. The core elements are 1. Defining the termination conditions (base examples), 2. Decomposing the problem and calling itself recursively (recursive examples). It is suitable for dealing with hierarchical structures, disassembling duplicate subproblems, or improving code readability, such as calculating factorials, traversing directories, etc. However, it is necessary to pay attention to the risks of memory consumption and stack overflow. When writing, the exit conditions should be clarified, the basic examples should be gradually approached, the redundant parameters should be avoided, and small inputs should be tested. For example, when scanning a directory, the function encounters a subdirectory and calls itself recursively until all levels are traversed.
