How to accelerate the laravel problem by Swoole

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.