mohammadraufzahed/tondbad-swoole
Composer 安装命令:
composer require mohammadraufzahed/tondbad-swoole
包简介
Tondbād - A lightweight and high-performance PHP framework built on OpenSwoole with routing, job workers, queue management, and gRPC support.
README 文档
README
TondbadSwoole is a high-performance, lightweight PHP framework built on OpenSwoole for creating asynchronous web applications, microservices, and gRPC servers. It offers a robust routing system, dependency injection, and support for gRPC, making it an ideal choice for modern PHP applications.
Features
- Asynchronous HTTP Server powered by OpenSwoole.
- FastRoute based routing system with attribute-based route definitions.
- Dependency Injection using a custom container for managing services and configurations.
- gRPC Support for building high-performance microservices.
- Monolog Integration for comprehensive logging to console and files.
- Graceful Shutdown to handle system signals (SIGTERM, SIGINT) and ensure smooth termination.
Requirements
- PHP 8.2 or higher
- OpenSwoole extension
- Composer
Installation
-
Clone the repository:
git clone https://github.com/yourusername/tondbad-swoole.git cd tondbad-swoole -
Install dependencies using Composer:
composer install
-
Install OpenSwoole:
pecl install openswoole
-
Configure the environment:
- Create a
.envfile in the root directory and configure necessary settings. For example:
PORT=8000 APP_ENV=local APP_DEBUG=true
- Create a
Usage
Running the HTTP Server
To start the HTTP server, run the following command:
composer server
This will start the OpenSwoole server on the configured port (default: 8000).
Running the gRPC Server
To start the gRPC server, use the command:
composer grpc
This will start the gRPC server for handling gRPC requests.
Defining Routes
Routes can be defined using PHP 8 attributes within your controllers. Here is an example of a route definition using the
#[Endpoint] attribute:
namespace App\Controllers; use TondbadSwoole\Core\Route\Attributes\Endpoint; use OpenSwoole\Http\Request; use OpenSwoole\Http\Response; class HomeController { #[Endpoint('GET', '/')] public function index(Request $request, Response $response) { $response->end('Welcome to TondbadSwoole!'); } #[Endpoint('POST', '/submit')] public function submit(Request $request, Response $response) { $response->end('Form Submitted!'); } }
Registering Routes
In your configuration file (config/routes.php), list the classes containing route definitions:
return [ \App\Controllers\HomeController::class, \App\Controllers\UserController::class, ];
Logging
TondbadSwoole uses Monolog for logging:
- Logs are written to the console (
php://stdout) and stored in a file (logs/app.log). - You can configure the logging settings in the
LoggerServiceProvider.
Log Levels
The default log level is DEBUG, capturing all levels of logs. You can change this level in the logger configuration.
Graceful Shutdown
The server will gracefully shut down on receiving SIGINT (Ctrl+C) or SIGTERM signals, allowing ongoing requests to
complete before stopping the server.
Compilation of Protocol Buffers (for gRPC)
To compile .proto files, run the following command:
composer compile-proto
This command will generate the necessary PHP files for gRPC communication.
Coming Soon
- Background Job Processing: The next version will include support for background job processing using OpenSwoole's TaskWorker, allowing you to handle long-running tasks efficiently in the background.
- Queue Management: Enhanced queue management for dispatching and handling background tasks.
Contributing
Feel free to submit issues or pull requests to improve this project. Contributions are welcome!
License
This project is licensed under the MIT License.
mohammadraufzahed/tondbad-swoole 适用场景与选型建议
mohammadraufzahed/tondbad-swoole 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「queue」 「routing」 「performance」 「php」 「gRPC」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mohammadraufzahed/tondbad-swoole 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mohammadraufzahed/tondbad-swoole 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mohammadraufzahed/tondbad-swoole 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
Write down your routing mapping at one place
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
Message queue statistics for OroPlatform
统计信息
- 总下载量: 74
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-19