Accelerating Laravel with Laravel‑s: Using Swoole for Significant Performance Gains

This article explains what Laravel‑s is, why it was needed to handle high‑traffic Baidu crawler loads, the measurable performance improvements achieved after integration, and provides step‑by‑step deployment and configuration guidance for Laravel projects using Swoole.

php Courses
php Courses
php Courses
Accelerating Laravel with Laravel‑s: Using Swoole for Significant Performance Gains

Laravel‑s is a glue project that quickly integrates Swoole into Laravel or Lumen, giving them much better performance; its source code is available on GitHub.

The motivation came when a Baidu mini‑program caused the crawler to generate extremely high QPS, saturating a 4‑core, 8 GB server’s CPU and 5 M bandwidth, leading to repeated crashes.

Initial attempts such as tuning php‑fpm, requesting Baidu to lower crawl rate, and load‑balancing across multiple servers provided limited relief, prompting the decision to accelerate HTTP responses with Laravel‑s.

Although exact QPS numbers were not recorded, after deploying Laravel‑s the CPU load dropped from 100 % to around 20 % and, after a temporary bandwidth upgrade to 15 M, stabilized at about 60 %, indicating at least a five‑fold performance improvement.

Deployment steps:

Create an empty Laravel project that only handles the crawled pages; expose it on a port such as 6501.

Deploy Laravel‑s and test the API with tools like ab.

Configure the original project to proxy the crawled page paths to the new project, e.g., 127.0.0.1:6501.

Example Nginx proxy configuration:

location ~ ^/v1/test.* {<br/>    proxy_pass http://127.0.0.1:6501;<br/>    proxy_set_header Host $host;<br/>}

Key considerations:

In conf/laravels.php the default number of workers is set to twice the number of CPU cores.

Laravel‑s runs on Swoole, so any code change requires restarting the laravel‑s process.

Because of this, database connections may not be released; enable persistent connections by adding the following to conf/database.php under the MySQL configuration:

'options' => [<br/>    // Enable persistent connections<br/>    \PDO::ATTR_PERSISTENT => true,<br/>],

Following these steps allows the Laravel application to handle high‑traffic scenarios more efficiently while keeping the original business logic intact.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPLaravelSwoole
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.