This article mainly introduces about how to use Swoole to accelerate laravel, has a certain reference value, now share to everyone, the need for friends can refer to
Let's go over it, the features of the parsing language that cause PHP to be slow are the culprit, plus all the files that are loaded when the request is released, so it becomes slower.
Later we have Opcache, using this, the request time will probably be shortened to the original half, but we will find that the time spent in fact seems to be a lot.
What is this for? The reason is, Opcache just omitted to parse the file time, actually run, we still need to go to the same code run again, specifically we can see:
Let's assume that if we run the code again and do not release it, then the next time we run again, it will save the time of repetition. Yes, indeed.
Here's the starting point:
1. Install laravel-swoole Extension
Composer require Swooletw/laravel-swoole
2, Swoole expansion of course is essential
PECL Install Swoole
Need to add to php.ini after installing swoole extension, do not repeat
3. Add the service provider in an array of config/app.php service providers:
Swooletw\http\laravelserviceprovider::class,
4. Now, you can execute the following command to start the Swoole HTTP service.
PHP Artisan swoole:http Start
AB test
Test environment: Ubuntu 18.04,4 core 8 thread 2.7~3.5ghz cpu,8g memory, 120G SSD
Test results:
AB parameter: ab-n 1000-c 100
We find that time per request is 2.512ms, of course, this is just a simple request and does not involve database queries. Overall, performance is better than Opcache, but this is a wild way, how many pits we do not know, and currently do not understand whether to use this for the production environment, but this idea is actually very good, and finally look forward to the official PHP as a research direction