workman 如果要統(tǒng)計 收發(fā)的流量情況,改怎么統(tǒng)計?
你可以加一個中間件,代碼類似
<?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請求字節(jié)數(shù)
echo strlen($request->rawBuffer())."\n";
$response = $next($request);
// http響應(yīng)字節(jié)數(shù)
echo strlen($response)."\n";
return $response;
}
}
你可以把數(shù)據(jù)存儲在磁盤上或者某個存儲里
這是基于 http協(xié)議的,我的想法是 基于tcp協(xié)議,我是可以統(tǒng)計 每條tcp命令的 收到的數(shù)據(jù)長度,但是 實際tcp的通信中 消耗的流量 肯定比 收到的數(shù)據(jù)大的