Webman
環(huán)境:
workerman/webman-framework 1.5.16
workerman/workerman dev-master (題外話,期待V5發(fā)布)
我想在當前請求的時候, 異步統(tǒng)計一些東西(可能有多重操作),所以打算序列化對象,異步消費去處理。
參數(shù)較多,所以不想一一拿出來處理 。 比如Request的路由,路由參數(shù),請求參數(shù)等。
發(fā)現(xiàn)直接調用
1.
serialize(request());
2.
$originReq = clone request();
serialize($originReq);
是會報錯的, 如下:
Exception: Serialization of 'Fiber' is not allowed。。
有看到建議在 入隊列前,賦值好需要的參數(shù)。。
但因為有同步處理時留下的代碼,直接依賴了Request,所以想最小化更改并優(yōu)化。
有沒有好的方法,能拿到request對象的序列化,或者轉化成字符串后,又能返回到原對象的方法???
demo:
Route::any('/test', function () {
$originReq = clone request();
echo serialize($originReq);
// 這里拿到序列化后的request, 扔進隊列。
return '';
})->setParams(['test' => 1]);
$originReq = request();
$newReq = new \support\Request($originReq->rawBuffer());
$newReq->route = $originReq->route;
echo serialize($newReq);
報錯:
Exception: Serialization of 'Closure' is not allowed
把這個對象 json成字符串 呢 試試 報錯不
'''
"connection":{"id":1,"status":2,"transport":"tcp","getRemoteIp":"127.0.0.1","remotePort":51816,"getRemoteAddress":"127.0.0.1:51816","getLocalIp":"127.0.0.1","getLocalPort":8787,"getLocalAddress":"127.0.0.1:8787","isIpV4":true,"isIpV6":false},"session":null,"properties":[],"plugin":"","app":"","controller":"app\controller\TestController","action":"query","route":{}}
'''
Route的setParams參數(shù)
“因為有同步處理時留下的代碼,直接依賴了Request,所以想最小化更改”。 架不住本來的同步代碼已經(jīng)實現(xiàn)了很多, 我只是優(yōu)化一下速度用異步,再加上幾個功能點。