Adjust the configuration of the framework itself
-
Edit env.
-
APP_ENV = production
-
APP_DEBUG = false
-
php artisan route:cache / php artisan config:cache
-
composer dump-autoload –optimize
-
php artisan optimize
Other possible
-
Open OPcache
-
Php-fpm configuration tuning
But… It’s easy to see on pressure tests, but it’s hard to see more than a tenfold improvement in performance
-
If you’re thinking about framework performance tuning, you probably already know enough about PHP. As you know, PHP releases all resources created during execution at the end of each request. This has a big advantage: PHP programmers rarely have to worry about freeing resources, such as memory, IO handles, database connections, etc. PHP will free up all of them at the end of the request. PHP programmers rarely have to worry about memory release, and it is difficult to write programs that leak memory. This makes PHP much simpler and easier to use and feels right. But there is a downside: PHP is hard to reuse resources between requests, and time-consuming work like PHP frameworks requires repeated requests — even if you’re doing the same thing every time. Because of this, the debate over whether or not to use frameworks has continued throughout PHP’s development.
-
Laravel itself requires a lot of files to boot, and is known for its eco-environment. In development, we will use many, many existing wheels, making the DISK IO very high at a boot, although the official PHP Artisan Optimize method optimized the file loading. But it doesn’t actually solve the IO problem. Now that you know the problem, it’s easy to fix, as long as you don’t reload every time you boot. Now Swoole.
-
The Swoole framework saves PHP frameworks and global objects from the performance penalty of being created and destroyed on every request compared to Apache/FPM. If your PHP code is a bare Echo, the Swoole framework has no performance advantage.
-
Again, there are always good and bad things. The downside: PHP is harder to program, you need to worry about memory release, and you need to care about how PHP uses memory. Even better, you need to know what frame to use so you don’t “accidentally” write surprising results. At the same time, PHP debugging becomes more difficult because you need to restart the process after each change to see the results. The benefit: the performance of the program is greatly improved. The objective upside, of course, is that PHP’s memory retrieval has been fairly stable and efficient, Swoole stability has been proven in quite a few projects, and Laravel code quality is quite high
Draw a cake
Scheme performance comparison using the wheel: Stone
The application type | The original Laravel | Stone-Web | Stone-Server | Native PHP directly echo |
---|---|---|---|---|
Laravel5 default page | 150 | 3000 | – | – |
Laravel5 simple interface | 150 | 3000 | 8500 | 9500 |
Laravel4 actual project simple page | 70 | 1000 | – | – |
Laravel4 simple interface | 120 | – | 8200 | 9500 |
Laravel4 Actual project home page | 35 | 380 | – | – |
-
All the above units are RPS
-
Stone is a considerable improvement over the original Laravel
-
Even when compared to a simple Echo, Stone’s performance loss is only about 10%
Swoole + Laravel do it!
PS: if pro or use PHP5 I will not take you to play ha
Pick a new ignition wheel: Laravel-s
Find a local project ab to test the waters and attach the results
Requests per second: 31.91 [#/ SEC]
First look at the Laravel-s documentation for a while configuration…
Requests per second: 592.17 [#/ SEC] (mean)
Ab-n 200-C 20 is the average of three times of pressure measurement performance improved by 20 times!!
You don’t have to spend 10 minutes to try it
Bingo, I can finally say PHP is the most beautiful language in the world in front of golang’s colleagues…
And then finally a swoop of water
Stress test Nginx static pages, Golang Http programs, and PHP7+Swoole Http programs using apache Bench tools. On the same machine, with a benchmark of 1 million concurrent Http requests, the QPS comparison is as follows:
software | QPS | Software version |
---|---|---|
Nginx | 164489.92 | Nginx / 1.4.6 (Ubuntu) |
Golang | 166838.68 | Go version go1.5.2 Linux/amd64 |
PHP7+Swoole | 287104.12 | Swoole – 1.7.22 – alpha |
Nginx – 1.9.9 | 245058.70 | Nginx / 1.9.9 |
Check it out From Swoole
Pay attention and don’t get lost
All right, everybody, that’s all for this article. All the people here are talented. As I said before, there are many technical points in PHP, because there are too many, it is really difficult to write, you will not read too much after writing, so I have compiled it into PDF and document, if necessary
Click on the code: PHP+ “platform”
As long as you can guarantee your salary to rise a step (constantly updated)
I hope the above content can help you. Many PHPer will encounter some problems and bottlenecks when they are advanced, and they have no sense of direction when writing too many business codes. I have sorted out some information, including but not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, YII2, Redis, Swoole, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc