workman 如果要统计 收发的流量情况,改怎么统计?

tgzmos

workman 如果要统计 收发的流量情况,改怎么统计?

1359 1 1
1个回答

walkor

你可以加一个中间件,代码类似

<?php
namespace app\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class Network implements MiddlewareInterface
{
    public function process(Request $request, callable $next) : Response
    {
        // http请求字节数
        echo strlen($request->rawBuffer())."\n";
        $response = $next($request);
        // http响应字节数
        echo strlen($response)."\n";
        return $response;
    }
}

你可以把数据存储在磁盘上或者某个存储里

  • tgzmos 2021-01-25

    这是基于 http协议的,我的想法是 基于tcp协议,我是可以统计 每条tcp命令的 收到的数据长度,但是 实际tcp的通信中 消耗的流量 肯定比 收到的数据大的

年代过于久远,无法发表回答
🔝