提交 0c8da756 编写于 作者: lzc828's avatar lzc828

使用go问题

上级 afd18936
...@@ -12,11 +12,10 @@ namespace One\Facades; ...@@ -12,11 +12,10 @@ namespace One\Facades;
* @method error($data, $k = 0, $prefix = 'error') static * @method error($data, $k = 0, $prefix = 'error') static
* @method setTraceId($id) static * @method setTraceId($id) static
* @method bindTraceId($id) static * @method bindTraceId($id) static
* @method flushTraceId() static * @method flushTraceId($go_id) static
* @method getTraceId() static * @method getTraceId() static
* *
*/ */
class Log extends Facade class Log extends Facade
{ {
protected static function getFacadeAccessor() protected static function getFacadeAccessor()
......
...@@ -4,6 +4,7 @@ namespace One\Http; ...@@ -4,6 +4,7 @@ namespace One\Http;
use One\Exceptions\HttpException; use One\Exceptions\HttpException;
use One\Facades\Log; use One\Facades\Log;
use SebastianBergmann\CodeCoverage\Report\PHP;
class Controller class Controller
{ {
...@@ -23,6 +24,8 @@ class Controller ...@@ -23,6 +24,8 @@ class Controller
*/ */
protected $server; protected $server;
protected $go_id = -1;
/** /**
* Controller constructor. * Controller constructor.
...@@ -31,15 +34,15 @@ class Controller ...@@ -31,15 +34,15 @@ class Controller
*/ */
public function __construct($request, $response, $server = null) public function __construct($request, $response, $server = null)
{ {
$this->go_id = get_co_id();
$this->request = $request; $this->request = $request;
$this->response = $response; $this->response = $response;
$this->server = $server; $this->server = $server;
} }
public function __destruct() public function __destruct()
{ {
Log::flushTraceId(); Log::flushTraceId($this->go_id);
} }
/** /**
......
...@@ -101,7 +101,9 @@ class Log ...@@ -101,7 +101,9 @@ class Log
public function setTraceId($id) public function setTraceId($id)
{ {
$this->_traceId[get_co_id()] = $id; $cid = get_co_id();
$this->_traceId[$cid] = $id;
return $cid;
} }
/** /**
...@@ -132,10 +134,9 @@ class Log ...@@ -132,10 +134,9 @@ class Log
/** /**
* 请求完成刷新 清除已经关闭的id * 请求完成刷新 清除已经关闭的id
*/ */
public function flushTraceId() public function flushTraceId($id)
{ {
if (_CLI_) { if (_CLI_) {
$id = get_co_id();
if (isset($this->_traceId[$id])) { if (isset($this->_traceId[$id])) {
unset($this->_traceId[$id]); unset($this->_traceId[$id]);
} }
......
...@@ -28,10 +28,13 @@ class TcpController ...@@ -28,10 +28,13 @@ class TcpController
*/ */
protected $session = null; protected $session = null;
protected $go_id = -1;
public function __construct($data, $server) public function __construct($data, $server)
{ {
$this->data = $data; $this->go_id = get_co_id();
$this->data = $data;
$this->server = $server; $this->server = $server;
if ($this->data->session_id) { if ($this->data->session_id) {
$this->session = new Session(null, $this->data->session_id); $this->session = new Session(null, $this->data->session_id);
...@@ -40,7 +43,7 @@ class TcpController ...@@ -40,7 +43,7 @@ class TcpController
public function __destruct() public function __destruct()
{ {
Log::flushTraceId(); Log::flushTraceId($this->go_id);
} }
} }
\ No newline at end of file
...@@ -27,16 +27,19 @@ class WsController ...@@ -27,16 +27,19 @@ class WsController
*/ */
protected $session; protected $session;
protected $go_id;
public function __construct($frame, $server, $session = null) public function __construct($frame, $server, $session = null)
{ {
$this->frame = $frame; $this->go_id = get_co_id();
$this->server = $server; $this->frame = $frame;
$this->server = $server;
$this->session = $session; $this->session = $session;
} }
public function __destruct() public function __destruct()
{ {
Log::flushTraceId(); Log::flushTraceId($this->go_id);
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册