Exemplo n.º 1
0
 public function __construct()
 {
     //添加开始时间钩子
     \Kerisy\Core\Hook::add("server_start", function () {
         $startTime = \Kerisy\Tool\RunTime::setStartTime();
         return $startTime;
     });
     parent::__construct();
 }
Exemplo n.º 2
0
 /**
  * 发送监控数据
  *
  * @param $tag
  * @param $group
  * @param string $msg
  * @return bool
  */
 public function send($tag, $group, $msg = '', $diffTime = '')
 {
     $configObj = new Config("config");
     $config = $configObj->get("monitor");
     if (!$config) {
         return false;
     }
     $obj = new Client($config['server']['host'], $config['server']['port']);
     if (!$diffTime) {
         $diffTime = RunTime::runtime();
     }
     $str = [];
     $str['name'] = $config['name'];
     $str['group'] = $group;
     $str['tag'] = $tag;
     $str['diff_time'] = $diffTime;
     $str['time'] = time();
     $str['msg'] = $msg;
     $obj->send(json_encode($str));
 }
Exemplo n.º 3
0
 /**
  * 异步写日志
  * @param $data
  * @param string $filename
  * @return bool
  * @throws Exception
  */
 static function info($data, $filename = "log.log")
 {
     $configObj = config("config");
     $path = $configObj->get("filelogpath");
     if (!$path) {
         throw new Exception("filelogpath not config");
     }
     $path = $path . "/" . KERISY_ENV . "/" . date('Y-m-d') . "/";
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     $filePath = $path . $filename;
     static $pid;
     $data = is_string($data) ? $data : json_encode($data);
     !$pid && ($pid = function_exists('posix_getpid') ? posix_getpid() : mt_rand(1, 9999));
     $ip = self::get_server_ip();
     $time = \Kerisy\Tool\RunTime::runtime();
     $newData = "[" . $ip . "]" . "[" . $pid . "]" . "[" . date('Y-m-d H:i:s') . "][cost:" . $time . "]" . $data;
     swoole_async_write($filePath, $newData . "\r\n");
     return true;
 }
Exemplo n.º 4
0
 protected function initializeConfig()
 {
     //开始执行时间
     \Kerisy\Tool\RunTime::setStartTime();
     date_default_timezone_set($this->timezone);
 }