AdapterMan: 使用workerman加速任意项目

众所周知,workerman是基于php cli的,由于php cli模式下无法使用php自带的header、sesion、cookie等函数,这导致将传统的php项目无法直接在workerman容器下直接运行。

我一度以为让传统业务在workerman中运行,就必须更改框架甚至业务代码以适配workerman,直到joanhey发了一个issue,打破了我的认知。

他们发布了一个名叫AdapterMan的项目,它可以做到不更改传统框架代码的情况下让你的传统php项目放到workerman中正常运行,并且他们公司已经在生产环境用了2年。

注意,是零代码改动直接让laravel、lumen、Slim等框架的项目在workerman上运行。

目前他们已经在laravel、lumen、Slim、Symfony、CakePHP、Yii2、KumbiaPHP 等做了初步压力测试,性能有很大的提升。

以下是压测结果

Laravel 8

FwPlaintextJsonSingle queryMultiple queryUpdatesFortunes
Laravel14,79914,7709,2633,2471,4528,354
Laravel Roadrunner482478474375359472
Laravel Swoole38,82437,43921,6873,9581,58816,035
Laravel Laravel s54,61749,37223,6772,9171,25516,696
Laravel Workerman103,00499,89146,0015,8281,66627,158
Laravel with Workerman % gain596.02%576.31%396.61%79.489%14.738%225.09%

146399c593440d

Symfony 6

146399c5cf5b1a

FwPlaintextJsonSingle queryMultiple queryUpdatesFortunes
Symfony38,23137,55712,57810,7413,42010,741
Symfony Workerman210,796197,059107,05013,4014,06271,092

Lumen 9

FwPlaintextJsonSingle queryMultiple queryUpdatesFortunes
Lumen18,99818,61610,7913,4961,4619,223
Lumen Swoole44,86143,59824,2554,1781,59916,854
Lumen Laravel s93,33582,74531,5673,0301,28221,130
Lumen Workerman185,126177,66758,7295,8571,66231,430

Slim with Workerman

Without ORM

FrameworkJSON1-query20-queryFortunesUpdatesPlaintext
Slim 438,30534,27212,57932,6342,09735,251
Slim 4 Workerman129,39381,88915,80373,2122,456134,531
Slim 4 Workerman pgsql * 102,92619,63792,75214,875

Lumen v9

146399c6a3914a

接入代码类似

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Adapterman\Adapterman;
use Workerman\Worker;

Adapterman::init();

$http_worker                = new Worker('http://0.0.0.0:8080');
$http_worker->count         = 8;
$http_worker->name          = 'AdapterMan';

$http_worker->onWorkerStart = static function () {
    //init();
    require __DIR__.'/start.php';
};

$http_worker->onMessage = static function ($connection, $request) {
    $connection->send(run());
};

Worker::runAll();

 

项目地址:https://github.com/joanhey/AdapterMan 强烈建议大家为其点赞(点星星)

相关链接:https://github.com/walkor/workerman/issues/824

原文转载自:https://www.workerman.net/q/9831

 
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享