百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

shadowfax

> 后端框架
开源

在 Swoole 上运行 Laravel。

350 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

在 Swoole 上运行 Laravel。

English | 中文

Shadowfax

The Shadowfax is a package that runs your Laravel application on Swoole.

Installation

You may use Composer to install Shadowfax to your project:

bash
composer require huang-yi/shadowfax

If you are using Lumen, you need to register the service provider manually in bootstrap/app.php:

php
$app->register(HuangYi\Shadowfax\ShadowfaxServiceProvider::class);

After installing Shadowfax, publish its configuration files using the shadowfax:publish Artisan command:

bash
php artisan shadowfax:publish

Configuration

The primary configuration file is shadowfax.yml. And this file name is added to the .gitignore file by shadowfax:publish Artisan command.

  1. Basic configuration:
  • name: The processes name.
  • type: The server type, support: http, websocket.
  • host: The server host.
  • port: The server port.
  • mode: The server mode, support: process, base.
  • access_log: Indicates whether to print the request information.
  • app_pool_capacity: Set the capacity of the apps pool. Only valid when coroutine is enabled.
  • framework_bootstrapper: Set Laravel bootstrap file. If you changed Laravel's directory structure, you should modify this value.
  1. server configuration:

This section defines the Swoole\Server configuration. Read the official docs for more information.

  1. abstracts configuration:

This option allows you to set a group of abstracts in the Laravel IoC container. These abstracts will be rebound after each request.

  1. controllers configuration:

This option allows you to clean the controller instances in route after each request.

yaml
controllers:
  - App\Http\Controllers\FooController
  - App\Http\Controllers\BarController
  1. cleaners configuration:

This option allows you to register custom cleaners. These cleaners will run after each request.

yaml
cleaners:
  - app/Cleaners/
  - CustomNamespace/FooCleaner
  1. db_pools configuration:

This option allows you to configure database connection pools. You can add multiple key-value pairs in here. The key name is a connection name in your database.connections, the key value is the connection pool capacity. e.g.:

yaml
db_pools:
  mysql: 3
  mysql2: 5
  1. redis_pools configuration:

This option allows you to configure redis connection pools. You can add multiple key-value pairs in here. The key name is a connection name in your database.redis, the key value is the connection pool capacity. e.g.:

yaml
redis_pools:
  default: 3
  1. controller server configuration:

This section defines the controller server configuration. The controller server allows you to stop or reload your Shadowfax.

Command

Shadowfax provides a shadowfax command to manage your server processes. This command is build on the Symfony console component, so you can run php shadowfax list for more information.

You may run the php shadowfax start command to start Shadowfax server. The --watch|-w option can run your Shadowfax in watch mode. In watch mode, the processes will be automatically reloaded when the files under your project change.

You must install the fswatch before using --watch|-w option.

The php shadowfax reload allows you to reload the Shadowfax processes.

The php shadowfax stop allows you to stop the Shadowfax server.

Database Connection Pool

Before using database connection pools, you must enable Swoole coroutine and configure the hook_flags:

yaml
server:
  enable_coroutine: true
  hook_flags: SWOOLE_HOOK_ALL

Then, add your connection to the db_pools option, and specify a pool capacity:

yaml
db_pools:
  mysql: 3
  mysql2: 5

Redis Connection Pool

The difference with database connection pool is that redis connection pools are configured under the redis_pools option.

yaml
redis_pools:
  default: 3

WebSocket Server

Shadowfax also allows you to build your WebSocket server.

First of all, you need to change the value of configuration item type to websocket. Then create a handler class that implemented the HuangYi\Shadowfax\Contracts\WebSocket\Handler interface:

…

And bind this handler to a uri in your route file:

php
use App\WebSocket\EchoServer;
use HuangYi\Shadowfax\Facades\WebSocket;

WebSocket::listen('/echo', new EchoServer);

Now, you can start the WebSocket server by command php shadowfax start.

Nginx Configuration

You may use Nginx as a reverse proxy in production environment:

…

You need to add the IP address of the Shadowfax to the App\Http\Middleware\TrustProxies Middleware.

Supervisor Configuration

If you want to use the Supervisor to manage your Shadowfax processes, the following configuration file should suffice:

ini
[program:shadowfax]
process_name=%(program_name)s
directory=/path/to/project
command=php shadowfax start
autostart=true
autorestart=true
user=www
redirect_stderr=true
stdout_logfile=/path/to/project/storage/logs/supervisor.log

Benchmarks

Run tests using wrk.

Environment 1

  • Hardware: 1 CPU, 4 Cores, 16GB Memory
  • MacOS 10.15.3
  • PHP 7.3.12 (with opcache)
  • Swoole 4.4.13
  • Laravel 7 (without session middleware)
  • Shadowfax 2.0.0 (with 20 worker processes)
bash
wrk -t4 -c200 http://127.0.0.1:1215/

Result:

bash
Running 10s test @ http://127.0.0.1:1215/
  4 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    26.44ms   31.44ms 212.73ms   84.28%
    Req/Sec     3.13k   839.99     6.07k    65.75%
  124418 requests in 10.01s, 312.06MB read
  Socket errors: connect 0, read 54, write 0, timeout 0
Requests/sec:  12430.20
Transfer/sec:     31.18MB

Environment 2

  • Hardware: 2 CPUs, 2 Cores, 4GB Memory
  • CentOS 7.5.1804
  • PHP 7.3.16 (with opcache)
  • Swoole 4.4.17
  • Laravel 7 (without session middleware)
  • Shadowfax 2.0.0 (with 10 worker processes)
bash
wrk -c100 http://127.0.0.1:1215/

Result:

bash
Running 10s test @ http://127.0.0.1:1215/
  2 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    25.06ms   12.11ms  85.92ms   60.94%
    Req/Sec     4.02k    41.46     4.08k    79.79%
  40321 requests in 10.08s, 101.13MB read
Requests/sec:   4001.76
Transfer/sec:     10.04MB

Testing

bash
composer test

License

Shadowfax is open-sourced software licensed under the MIT license.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPcoroutinehttplaravellaravel-swoole

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架