MixPHP 公布 v3.0.27 反对 Swow

更新内容

  • 减少 Swow 反对
  • 减少 WebSocket, GRPC 的 swoolecopool 过程池反对

体验 Swow

本次更新次要反对了 Swow, 市面上唯二反对 Swow 的框架

装置

composer create-project --prefer-dist mix/api-skeleton api

运行

还没有装置 Swow 的能够参考文档先装置 Install, Swow 当初还未处于正式版能够先尝鲜体验
php bin/swow.php                               ____ ______ ___ _____ ___   _____  / /_ _____  / __ `__ \/ /\ \/ /__ / __ \/ __ \/ __ \ / / / / / / / /\ \/ _ / /_/ / / / / /_/ //_/ /_/ /_/_/ /_/\_\  / .___/_/ /_/ .___/                     /_/         /_/System    Name:       linuxPHP       Version:    8.0.15Swow      Version:    0.1.0Listen    Addr:       http://0.0.0.0:95012022-04-16 20:32:00.415403  INFO  Start swow coroutine server

测试 Swow 性能

在性能上是优于 SwooleCoroutine 在将来的性能中也会反对协程Mongo, 多过程协程

wrk -c1000 -t10 http://localhost:9501Running 10s test @ http://localhost:9501  10 threads and 1000 connections  Thread Stats   Avg      Stdev     Max   +/- Stdev    Latency    54.09ms    2.97ms 124.98ms   97.74%    Req/Sec     1.84k   156.88     2.02k    92.32%  182698 requests in 10.08s, 9.06MB read  Socket errors: connect 0, read 830, write 0, timeout 0Requests/sec:  18128.02Transfer/sec:      0.90MB

体验 Swow-WebSocket

编辑 bin/swow.php while 局部代码就能够

while (true) {    $request = null;    try {        $request = $connection->recvHttpRequest();        if (($upgrade = $request->getUpgrade()) && $upgrade === $request::UPGRADE_WEBSOCKET) {            $connection->upgradeToWebSocket($request);            while (true) {                $frame = $connection->recvWebSocketFrame();                $opcode = $frame->getOpcode();                switch ($opcode) {                    case WebSocketOpcode::PING:                        $connection->sendString(WebSocketFrame::PONG);                        break;                    case WebSocketOpcode::PONG:                        break;                    case WebSocketOpcode::CLOSE:                        break 2;                    default:                        $frame = new WebSocketFrame();                        $frame->setPayloadData('Hello Swow!');                        $connection->sendWebSocketFrame($frame);                }            }            break;        }        $handler = $this->handler;        $handler($request, $connection);    } catch (ResponseException $exception) {        $connection->error($exception->getCode(), $exception->getMessage());    }    if (!$request || !$request->getKeepAlive()) {        break;    }}

链接 WebSocket 发送内容 hello 收到回复 hello Swow! 通过 jmeter 测试 SwowWebSocket的性能也是相当恐怖的

对于MixPHP

MixPHP 是一个 PHP 命令行模式开发框架;基于 Vega 驱动的 HTTP 能够同时反对 Swoole、Swow、WorkerMan、FPM、CLI-Server 生态,并且能够无缝切换。 你能够只应用 mix/vega 来搭配 laravel orm 应用;能够在任意环境中应用 mix/database 和 mix/redis;能够应用 mix/grpc 原生代码编写 gRPC;所有的模块你能够像搭积木一样随便组合。性能强劲在 TechEmpower Benchmark霸榜前十。

开箱即用, 灵便组合

当咱们在本地开发时, 没有装置 Swow/Swoole 能够应用 cli/fpm 本地开发, 上线应用 Swoole/Swow/Workerman 应用框架不必放心底层切换。

反对多种服务器驱动,并且能够无缝切换。

  • PHP Built-in CLI-Server 零扩大依赖 热更新 适宜本机开发
  • PHP-FPM 热更新 适宜共享开发 适宜 admin 开发
  • Swoole 常驻内存 兼容 composer 生态
  • Swoole Coroutine 常驻内存 协程性能强劲
  • Swow 常驻内存 纯协程引擎
  • WorkerMan 常驻内存 兼容 composer 生态

官网及交换

https://github.com/mix-php/mix (点Star反对一下)

https://gitee.com/mix-php/mix (点Star反对一下)

OpenMix技术交换A群: 284806582 (暗号:phper)

OpenMix技术交换A群: 825122875 (暗号:phper)