reactphp-x/laravel-zero
Composer 安装命令:
composer create-project reactphp-x/laravel-zero
包简介
The Reactphp Framework build top of Framework X and Larave zero.
README 文档
README
reactphp-x基于 laravel-zero 和 reactphp 的异步web框架
install
composer create-project reactphp-x/reactphp-x dev-master -vvv
config
cp .env.example .env
启动项目
php artisan reactphp:http start
visit
Documentation
Route
routes/api.php
use ReactphpX\LaravelReactphp\Facades\Route; use React\Http\Message\Response; use Psr\Http\Message\ServerRequestInterface; Route::get('/', function (ServerRequestInterface $request) { return Response::plaintext( "Hello wörld!\n" ); }); $class = new class { public function index(ServerRequestInterface $request) { return Response::plaintext( "Hello wörld!\n" ); } }; Route::get('/at', get_class($class).'@index'); // Route::get('/controller', 'App\Http\Controllers\IndexController@index'); $middlware1 = function ($request, $next) { // todo middleware return $next($request); }; $middlware2 = function ($request, $next) { // todo middleware return $next($request); }; Route::group('/users', $middlware1, $middlware2, function () { Route::get('/', function (ServerRequestInterface $request) { return Response::plaintext( "Hello wörld!\n" ); }); Route::get('/{id}', function (ServerRequestInterface $request) { $id = $request->getAttribute('id'); return Response::plaintext( "Hello wörld! $id\n" ); }); }); Route::middleware($middlware1,$middlware2)->group('/users', function () { Route::get('/', function (ServerRequestInterface $request) { return Response::plaintext( "Hello wörld!\n" ); }); Route::get('/{id}', function (ServerRequestInterface $request) { $id = $request->getAttribute('id'); return Response::plaintext( "Hello wörld! $id\n" ); }); });
Middleware
use App\Http\Middlewares\ExampleMiddleware; Route::middleware(ExampleMiddleware::class)->group('/users', function () { Route::get('/', function (ServerRequestInterface $request) { return Response::plaintext( "Hello wörld!\n" ); }); });
Request Params
// 获取请求头 $serverParams = $request->getServerParams(); // 获取请求参数 $queryParams = $request->getQueryParams(); // Content-Type: application/x-www-form-urlencoded or Content-Type: multipart/form-data $name = $request->getParsedBody()['name'] ?? 'World'; // Content-Type: application/json $data = json_decode((string)$request->getBody());
Controller
use App\Http\Controllers\ExampleController; Route::get('/example', ExampleController::class.'@index');
cron
routes/cron.php 默认开启,在 config/cron.php 设置 enabled=false 关闭
/** * Finds next execution time(stamp) parsin crontab syntax. * * @param string $crontab_string : * 0 1 2 3 4 5 * * * * * * * * - - - - - - * | | | | | | * | | | | | +----- day of week (0 - 6) (Sunday=0) * | | | | +----- month (1 - 12) * | | | +------- day of month (1 - 31) * | | +--------- hour (0 - 23) * | +----------- min (0 - 59) * +------------- sec (0-59) */ new Crontab('* * * * * *', function () { echo 'every_second: '. date('Y-m-d H:i:s') . "\n"; });
异步ORM
请参考 https://github.com/reactphp-x/orm,该项目已集成
使用之前先配置数据库
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=123456
DB_DATABASE=xxxx
License
MIT
reactphp-x/laravel-zero 适用场景与选型建议
reactphp-x/laravel-zero 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 08 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「cli」 「console」 「laravel」 「reactphp」 「Laravel Zero」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 reactphp-x/laravel-zero 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reactphp-x/laravel-zero 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 reactphp-x/laravel-zero 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This class provides you with an easy-to-use interface to progress bars.
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A Laravel package to retrieve data from Google Search Console
Additional artisan commands for Laravel
A table generator class for the PHP CLI.
Slim starter / Slim skeleton package to boost your development with Slim framework
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-09