as everyone knows ,PHP The heavier the frame , The lower the performance , Because the heavy-duty framework calls a lot of classes when parsing 、 Methods and custom functions , Resulting in a serious performance degradation .
Laravel It's a very popular PHP frame , But it's also a heavy-duty full stack framework , You can use This method To test your Laravel Application performance , The effect is not ideal .
Of course Laravel There's also a sister version ：Lumen, This is similar to Slim The micro framework of , If you think this micro framework is enough to use , Can be used as an alternative Laravel.
Fortunately PHP7 be relative to PHP5.6 for , Performance has nearly doubled , and Facebook Of HHVM It's also a good alternative . So if possible , Use the latest version as much as possible PHP, The benefit is not a star and a half .
But for the Laravel For these heavy frames , That is to use PHP7/HHVM, The performance is still very low , Even with caching （ such as memcached/redis etc. ） It can relieve the server pressure , But it just increases the speed of static pages , about Eloquent ORM This is a performance intensive place , Or palliative （ Of course you can use DB Facade replacement , Refer to my question ）, There's no way out ？（ Some people say opcache, But it's for Laravel The effect of the framework is not very good ）
No ！ You need Stone！
Stone What is it? ？ This is the author in PHPHub The post above （https://learnku.com/laravel/t/2092/5-minutes-to-improve-the-performance-of-laravel-frame-more-than-10-times）, see Stone Project address （https://github.com/StoneGroup/stone） And documentation （https://chefxu.gitbooks.io/stone-docs/content/）.
The following is the PHP7 Method of installation ：
My test environment is Debian Linux 8 64 position ,OSX It's fine too （ use homebrew install Nginx and PHP7, Other operations are shown below ）, Not recommended Windows, Because compiling and extending is relatively troublesome .
use Debian/Ubuntu/Linux mint have access to dotdeb Source , There's the latest version of Nginx,PHP7,MySQL/MariaDB. Of course I won't tell you , I use it OpenResty, The installation process is not detailed , No, please Google.
First installation swoole and runkit Expand .
pecl install swoole
PHP7 The pit here is , If you use this source to install PHP7, because PEAR Not the latest version , You may encounter this issues The problem described , resolvent ：
wget http://pear.php.net/go-pear.phar php go-pear.phar
At the time of writing ,runkit Extension does not support PHP7, So don't use pecl install , The compiler will make mistakes . But someone has made a modified version to use , See this issues.
Installation method ：
git clone https://github.com/runkit7/runkit7.git cd runkit7 phpize ./configure make sudo make install
At this point, both extensions have been installed successfully .
Then follow your example PHP7 The actual path to write ini file , load swoole and runkit. as for Windows perhaps OSX use homebrew For installation , Change directly php.ini That's it .
Use Dotdeb Source installed PHP7 The path is a /etc/php/7.0/, So my order is ：
sudo echo extension=swoole.so >> /etc/php/7.0/cli/conf.d/20-swoole.ini sudo echo extension=swoole.so >> /etc/php/7.0/fpm/conf.d/20-swoole.ini sudo echo extension=runkit.so >> /etc/php/7.0/cli/conf.d/20-runkit.ini sudo echo extension=runkit.so >> /etc/php/7.0/fpm/conf.d/20-runkit.ini
Then install Stone:composer require stone/kernel:dev-master
The last restart php-fpm, Reuse php -m have a look , These two extensions loaded successfully .
Next steps , Just follow the document , Here we are Stone stay PHP7 It was installed successfully ！ start-up Stone, Enjoy the leap in performance ！
PS： Find another similar project , But the details are different , You can have a look at what you are interested in ：https://github.com/scil/LaravelFly
Focus , Neverlost
All right, everyone , The above is the whole content of this article , You can see the people here , All are personnel . I said before ,PHP There are many technical points in this aspect , It's also because there are so many , I can't write it down , We won't read too much after writing it , So I've organized it into PDF And documentation , If you need anything, you can
More learning can be found in 【 Benchmarking big factories 】 The high-quality goods PHP Architect tutorial catalog , As long as you can finish it, make sure your salary goes up one step （ Continuous updating ）
I hope the above will help you , quite a lot PHPer There are always some problems and bottlenecks in the advanced stage , There is no sense of direction in the business code , I don't know where to start to improve , I've compiled some information about it , Including but not limited to ： Distributed architecture 、 Highly scalable 、 High performance 、 High concurrency 、 Server performance tuning 、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql Optimize 、shell Script 、Docker、 Microservices 、Nginx If you need advanced advanced dry goods, you can share them for free , You can join me if you need PHP Technology exchange group