/** * @desc 致命错误的捕获 **/ public function throwParseError() { $error = error_get_last(); if ($error && in_array($error['type'], array(1, 4, 16, 64, 256, 4096, E_ALL))) { $error = array('code' => $error['type'], 'msg' => $error['message'], 'trace' => $error['file'] . ' In Line:' . $error['line'], 'data' => '', 'runTime' => RunTime::getTime()); $this->pushError($error); $this->renderError($error); } }
/** * 格式化数据结构 * @author 孟伟 * @datetime 2015年07月28日15:35:47 * * @param string $data * @param int $code * @param string $msg * @return array */ public function outputData($data = '', $code = 200, $msg = '') { if (is_object($data)) { $data = $data->toArray(); } $resultData = array('code' => $code, 'msg' => $msg, 'runTime' => RunTime::getTime(1)); if (isset($data['count'])) { $resultData['count'] = $data['count']; unset($data['count']); } $resultData['data'] = $data; return $resultData; }
public function afterDispatch(Event $event, \Phalcon\Mvc\Dispatcher $dispatcher) { $app = self::getProject(); if (strpos($app, 'gc.operator') === false && strpos($app, 'gc.front') === false) { return; } $di = DI::getDefault(); $router = $di['router']; $module = $router->getModuleName(); $controller = $router->getControllerName(); $action = $router->getActionName(); $uri = $module . '\\' . $controller . '\\' . $action; $code = intval($di['response']->getStatusCode()); $monitor = $di['config']->swoole_monitor; $client = new \swoole_client(intval($monitor->protocol)); $connect = $client->connect($monitor->host, $monitor->port, $monitor->timeout); $data = ['project' => self::getProject(), 'service' => trim($uri, '\\'), 'action' => '', 'timeStamp' => time(), 'runTime' => RunTime::getTime(), 'code' => empty($code) ? 200 : $code, 'errorSummary' => '', 'serviceIp' => self::getLocalip(), 'baseIp' => '', 'errorDetail' => array()]; $client->send(json_encode($data)); $client->close(); }
public function errorCallback($type, $error, $callinfo) { if (is_array($error)) { self::$result[$callinfo['sequence']]['code'] = $error['code'] ? $error['code'] : 600; self::$result[$callinfo['sequence']]['msg'] = $error['message']; self::$result[$callinfo['sequence']]['trace'] = $error['file'] . ' In line:' . $error['line']; } else { self::$result[$callinfo['sequence']]['code'] = '600'; self::$result[$callinfo['sequence']]['msg'] = $error; self::$result[$callinfo['sequence']]['trace'] = ''; } self::$result[$callinfo['sequence']]['data'] = ''; self::$result[$callinfo['sequence']]['runTime'] = RunTime::getTime(); $this->pushError($this->rawData[$callinfo['sequence']], self::$result[$callinfo['sequence']]); }