Setting Up LaravelS with Swoole in Laradock and Performance Comparison

This tutorial walks through installing LaravelS with Swoole using Laradock, configuring Nginx and Docker, adjusting PHP versions, running AB performance tests, and shows that the request‑per‑second results are comparable to a standard Laravel 9 setup.

php Courses
php Courses
php Courses
Setting Up LaravelS with Swoole in Laradock and Performance Comparison

Introduction: The author wanted to try Swoole with WebSocket and compare Laravel 9 performance using Laradock, noting that the results were similar to vanilla Laravel.

Installation of LaravelS in Laradock: modify the .env file to use PHP 8.1 (or higher), then rebuild the containers with docker‑compose build and verify the installation.

Configure Laravel's HTTP server:

Install a Laravel project (e.g., curl -s "https://laravel.build/laravel9" | bash).

Require the LaravelS package: composer require hhxsv5/laravel-s.

Publish LaravelS configuration: php artisan laravels publish.

Set up Nginx to route static resources to Nginx and dynamic requests to LaravelS with the following server block (code shown as‑is):

upstream laravels {<br/>    # Connect IP:Port<br/>    server workspace:5200 weight=5 max_fails=3 fail_timeout=30s;<br/>    keepalive 16;<br/>}<br/>server {<br/>    listen 80;<br/>    server_name swoole.test;<br/>    root /var/www/laravel9/public;<br/>    index index.php index.html index.htm;<br/>    location / {<br/>        try_files $uri @laravels;<br/>    }<br/>    location @laravels {<br/>        proxy_http_version 1.1;<br/>        proxy_set_header Connection "";<br/>        proxy_set_header X-Real-IP $remote_addr;<br/>        proxy_set_header X-Real-PORT $remote_port;<br/>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br/>        proxy_set_header Host $http_host;<br/>        proxy_set_header Scheme $scheme;<br/>        proxy_set_header Server-Protocol $server_protocol;<br/>        proxy_set_header Server-Name $server_name;<br/>        proxy_set_header Server-Addr $server_addr;<br/>        proxy_set_header Server-Port $server_port;<br/>        proxy_pass http://laravels;<br/>    }<br/>    error_log /var/log/nginx/swoole_test_error.log;<br/>    access_log /var/log/nginx/swoole_test_access.log;<br/>}

Additional configuration includes adding to the Laravel .env file:

LARAVELS_LISTEN_IP=workspace<br/>LARAVELS_DAEMONIZE=true

Configure a regular Laravel site with its own Nginx server block (code omitted for brevity) and update the local /etc/hosts file: 127.0.0.1 swoole.test laravel.test Rebuild the Docker containers:

docker compose stop<br/>docker compose build workspace nginx<br/>docker compose up -d redis mysql nginx workspace

Enter the workspace container to start LaravelS: docker exec -it d4940755a928 /bin/bash Performance testing with ApacheBench (AB): two scenarios were run – 100 total requests with concurrency 10, and 1000 total requests with concurrency 20 – comparing Swoole‑backed LaravelS against plain Laravel 9. The request‑per‑second numbers were close, sometimes even favoring Laravel 9, indicating no clear performance advantage.

Conclusion: Using LaravelS with Swoole in a Laradock environment does not produce a significant throughput increase over a standard Laravel 9 setup under the tested conditions.

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.

LaravelSwoole
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.