reactphp-x / framework
A lightweight application framework integrating Framework X with reactphp-x workers.
dev-master
2026-07-16 09:14 UTC
Requires
- php: >=8.1
- clue/framework-x: ^0.17
- react/http: ^1.11
- react/socket: ^1.16
- reactphp-x/worker: dev-master
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- phpunit/phpunit: ^10.5 || ^11.0
This package is auto-updated.
Last update: 2026-07-16 09:14:22 UTC
README
一个面向 PHP CLI 常驻进程的基础框架包,组合以下组件:
- Framework X:HTTP 路由与中间件
reactphp-x/worker:多进程 HTTP Worker 管理和信号重载vlucas/phpdotenv:.env配置加载
要求
- PHP 8.1+
- Linux/macOS(不支持 Windows worker 模式)
pcntl、posix扩展
安装
composer require reactphp-x/framework
当前 reactphp-x/worker 只发布了 dev-master,因此项目需要允许 dev 稳定级别并优先选择稳定版本:
{
"minimum-stability": "dev",
"prefer-stable": true
}
快速开始
复制环境配置:
cp .env.example .env
创建启动文件:
<?php use FrameworkX\App; use React\Http\Message\Response; use ReactphpX\Framework\Application; use ReactphpX\Framework\Environment; require __DIR__ . '/vendor/autoload.php'; $server = Application::create(__DIR__); $server->http(static function (Environment $env): App { $app = new App(); $app->get('/', static fn () => Response::plaintext("Hello\n")); return $app; }); if ($server->environment()->string('APP_ENV', 'production') === 'development') { $server->fileReload([__DIR__ . '/app', __DIR__ . '/config']); } $server->run();
启动及管理命令由 reactphp-x/worker 提供:
php start.php start php start.php start -d php start.php status php start.php reload php start.php stop
仓库内的完整示例可通过 php examples/start.php start 启动。
文件重载
fileReload() 参考 game-needle 的 FileMonitor Worker 实现:
- 只在非 daemon 模式启用
- 监控 PHP 文件的新增、修改和删除
- 自动跳过
.git与vendor - 检测到变化后向 master 发送
SIGUSR1 - FileMonitor 自身不可重载,仅重载 HTTP Worker
配置
可用配置及默认值见 .env.example。phpdotenv 使用 immutable 模式加载 .env,不会覆盖操作系统已经提供的环境变量。