public function publish_message($topic, $message, $partition = 0) { $stime = microtime(true); $rtn = false; $offset = false; if (!is_string($message)) { $message = json_encode($message); } $p = $this->getProducer(); $p->setRequireAck($this->producerRequireAck); $p->setMessages($topic, $partition, $message); try { $result = $p->send(); } catch (\Exception $e) { $catched_exception = $e; \Libs\Log\LevelLogWriter::warning("send to kafka failed,msg:" . $e->getMessage(), $e->getCode()); $rtn = false; } if ($result && isset($result[$topic][$partition]['errCode']) && $result[$topic][$partition]['errCode'] == 0) { $rtn = $offset = $result[$topic][$partition]['offset']; } else { $rtn = false; } $logData = array(); $logData['zk'] = $this->zkHosts; $logData['topic'] = $topic; $logData['message'] = $message; $logData['partition'] = $partition; $logData['offset'] = $offset; $logData['exception'] = isset($catched_exception) ? json_encode($catched_exception) : ''; $logData['timecost'] = number_format((microtime(true) - $stime) * 1000, 2); \Libs\Log\LevelLogWriter::selfLog("mqclient", "publish_message", $logData); return $rtn; }
public static function log($tag = "") { Profiler::over(); $data = array(); $data['tag'] = $tag; $data['data'] = serialize(Profiler::getTopNodes()); $data['memuseage'] = Profiler::getMemUsage(); $data['memuseage'] = $data['memuseage']['num'] . ' ' . $data['memuseage']['unit']; $data['total_cost'] = Profiler::getGlobalDuration(); \Libs\Log\LevelLogWriter::selfLog("profiler", "PROFILER", $data); return $data; }
private function rpclog($ch) { $curlErrno = curl_errno($ch); $curlError = curl_error($ch); $info = curl_getinfo($ch); $logInfo = array(); $logInfo['curl_errno'] = $curlErrno; $logInfo['curl_error'] = $curlError; $logInfo['url'] = $info['url']; $logInfo['http_code'] = $info['http_code']; $logInfo['total_time'] = number_format($info['total_time'] * 1000, 0); $logInfo['time_detail'] = number_format($info['namelookup_time'] * 1000, 0) . "," . number_format($info['connect_time'] * 1000, 0) . "," . number_format($info['pretransfer_time'] * 1000, 0) . "," . number_format($info['starttransfer_time'] * 1000, 0); \Libs\Log\LevelLogWriter::selfLog('rpc', "", $logInfo); }