forge-templates/php-openswoole-kit
Composer 安装命令:
composer create-project forge-templates/php-openswoole-kit
包简介
Production-ready PHP OpenSwoole boilerplate with clean architecture, request/response layer, and scalable structure.
README 文档
README
A high-performance, production-ready OpenSwoole HTTP server skeleton built with modern PHP architecture principles.
This project follows a clean architecture approach, using PSR-4 autoloading, strict separation of concerns, structured logging, and a lightweight routing system optimized for high concurrency workloads.
Features
- High-performance OpenSwoole HTTP server
- PSR-4 autoloading (no manual
requirein app layer) - Clean architecture (Http / Routing / Support / Controllers)
- Centralized configuration system
.envsupport viaphpdotenv- Production-grade logging (Monolog with rotating files)
- Global error & exception handling (Laravel-like behavior)
- Lightweight router with dynamic routes (
/users/{id}) - JSON-first API response layer
- Stateless request lifecycle (optimized for workers)
- Ready for horizontal scaling
📁 Project Structure
project/
├─ bootstrap/
│ └─ app.php # App bootstrap (env + config loader)
├─ public/
│ └─ server.php # Entry point (OpenSwoole server)
├─ config/
│ └─ config.php # Central configuration
├─ app/
│ ├─ Http/
│ │ ├─ Controllers/ # Application controllers
│ │ ├─ Request.php # Request abstraction
│ │ └─ Response.php # Response abstraction
│ ├─ Routing/ # Core routing engine
│ ├─ Routes/ # Route registration layer
│ └─ Support/ # Env, Logger, Error handling
├─ storage/
│ └─ logs/ # Application logs
├─ .env
└─ composer.json
Requirements
- PHP 8.2+
- OpenSwoole extension
- Composer
Installation
composer create-project forge-templates/php-openswoole-kit
Environment Setup
Run :
cp .env.example .env
Or create .env file in the project root:
APP_NAME="My OpenSwoole Service" APP_ENV=production APP_DEBUG=false APP_TIMEZONE=Asia/Aden HOST=0.0.0.0 PORT=8077 MAX_REQUEST=10000 REQUEST_TIMEOUT_MS=30000 REQUEST_BODY_SIZE_LIMIT=2097152 RATE_LIMIT_WINDOW_MS=60000 RATE_LIMIT_MAX=60 LOG_LEVEL=info LOG_DAYS=14
Running the Server
php public/server.php
You should see:
[PRODUCTION] My OpenSwoole Service started on 0.0.0.0:8077
🧠 Architecture Overview
1. Bootstrap Layer
- Loads Composer autoload
- Loads
.env - Builds configuration array
2. Configuration Layer
- Centralized config via
config/config.php - Environment values injected through
Envhelper - No direct
getenv()usage in business logic
3. HTTP Layer
Requestwraps OpenSwoole requestResponsehandles output (JSON / Text / HTML)- Stateless per request lifecycle
4. Routing Layer
-
Static + dynamic routes supported
-
Supports:
/users/{id}/api/*
-
Clean controller binding
5. Support Layer
- Global error handler (exceptions, fatal errors)
- Structured logging (Monolog)
- Central environment helper
Routing Example
$router->get('/health', HealthController::class); $router->get('/users/{id}', UserShowController::class);
Controller example:
final class HealthController { public function __invoke(Request $req, Response $res): void { $res->json([ 'status' => 'ok', ]); } }
Logging
Logs are stored in:
storage/logs/app.log
Features:
- Rotating logs
- Structured output
- Error + exception capture
- Production-safe format
Error Handling
- Global exception handler
- Fatal error capture
- Debug mode support
- Production-safe JSON error responses
Performance Notes
Designed for:
- Long-running OpenSwoole workers
- High concurrency traffic
- Minimal per-request overhead
- No repeated bootstrapping per request
🔐 Security Notes
- Sensitive values stored in
.env - Config layer isolates environment access
- Body size limits enforced
- Safe JSON decoding
- Controlled error output in production
📄 License
MIT
forge-templates/php-openswoole-kit 适用场景与选型建议
forge-templates/php-openswoole-kit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 forge-templates/php-openswoole-kit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 forge-templates/php-openswoole-kit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 45
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-16