antidot-fw/reactive-starter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

antidot-fw/reactive-starter

Composer 安装命令:

composer create-project antidot-fw/reactive-starter

包简介

Reactive Antidot Framework Apllication Starter

README 文档

README

link-packagist

This framework is based on concepts and components of other open source software, especially Zend Expressive, Zend Stratigillity, Recoil and React PHP.

Installation

Install a project using composer package manager:

composer create-project antidot-fw/reactive-starter dev
mv dev/.* dev/* ./ && rmdir dev
bin/console server:run

Open your browser localhost on port 5555 and you will see the DriftPHP Server up and running.

Config

Server Config

Default config

parameters:
    server:
      host: '0.0.0.0'
      port: '5555'
      max_concurrency: 100
      buffer_size: 4096
      workers: 4

Development Mode

To run it in dev mode you can run config:development-mode command

bin/console config:development-mode

Or you can do it by hand renaming from config/services/dependencies.dev.yaml.dist to config/services/dependencies.dev.yaml

mv config/services/dependencies.dev.yaml.dist config/services/dependencies.dev.yaml

Hot Code Reloading

composer require seregazhuk/php-watcher --dev

You can use Php whatcher with composer for more friendly development.

bin/console server:watch

Default homepage

Open another console and check the built-in Cli tool

bin/console

Default console tool

Async Usage

It allows executing promises inside PSR-15 and PSR-7 Middlewares and request handlers

PSR-15 Middleware

<?php
declare(strict_types = 1);

namespace App;

use Antidot\React\PromiseResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        return new PromiseResponse(
            resolve($request)->then(static fn(ServerrequestInsterface $request) => $handler->handle($request))
        );
    }
}

PSR-7 Request Handler

<?php
declare(strict_types = 1);

namespace App;

use Antidot\React\PromiseResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements RequestHandlerInterface
{
    public function process(ServerRequestInterface $request): ResponseInterface
    {
        return resolve($request)->then(
            function(ServerrequestInterface $request): ResponseInterface {
                return new Response('Hello World!!!');
            }
        );;
    }
}

Classic Usage

It allows executing classic PSR-15 middleware and request handler:

PSR-15 Middleware

<?php
declare(strict_types = 1);

namespace App;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        return $handler->handle($request);
    }
}

PSR-7 Request Handler

<?php
declare(strict_types = 1);

namespace App;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class SomeMiddleware implements RequestHandlerInterface
{
    public function process(ServerRequestInterface $request): ResponseInterface
    {
        return new Response('Hello World!!!');
    }
}

Benchmark

Using apache ab with single thread:

> ab -n 40000 -c 64 http://127.0.0.1:8080/ 
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)

Server Software:        ReactPHP/1
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /
Document Length:        96 bytes

Concurrency Level:      64
Time taken for tests:   16.201 seconds
Complete requests:      40000
Failed requests:        0
Total transferred:      8960000 bytes
HTML transferred:       3840000 bytes
Requests per second:    2468.93 [#/sec] (mean)
Time per request:       25.922 [ms] (mean)
Time per request:       0.405 [ms] (mean, across all concurrent requests)
Transfer rate:          540.08 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:    15   26   1.4     25      33
Waiting:       15   26   1.4     25      33
Total:         16   26   1.4     25      33

Percentage of the requests served within a certain time (ms)
  50%     25
  66%     25
  75%     26
  80%     26
  90%     27
  95%     29
  98%     31
  99%     32
 100%     33 (longest request)

using wrk:

> wrk -t8 -c64 -d15s http://127.0.0.1:8080/                                                                                                                                                                                                         [95ba8e6]
Running 15s test @ http://127.0.0.1:8080/
  8 threads and 64 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    26.14ms    1.44ms  34.63ms   92.76%
    Req/Sec   306.84     24.52   373.00     81.17%
  36670 requests in 15.04s, 8.50MB read
Requests/sec:   2437.45
Transfer/sec:    578.42KB

See ranking in The Benchmarker - Web Framework project.

antidot-fw/reactive-starter 适用场景与选型建议

antidot-fw/reactive-starter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 14, 最近一次更新时间为 2019 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 antidot-fw/reactive-starter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 antidot-fw/reactive-starter 我们能提供哪些服务?
定制开发 / 二次开发

基于 antidot-fw/reactive-starter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2019-11-23