static function log($category, $message) { require_once THRIFT_ROOT . '/Thrift.php'; require_once THRIFT_ROOT . '/protocol/TBinaryProtocol.php'; require_once THRIFT_ROOT . '/transport/TSocket.php'; require_once THRIFT_ROOT . '/transport/TFramedTransport.php'; require_once THRIFT_ROOT . '/packages/scribe/scribe.php'; switch ($category) { case 'general': case 'accounts': case 'actions': case 'status': case 'security': case 'debug': case 'history': case 'regulation': case 'specials': break; default: fatal(); } if (!is_string($message)) { if (is_array($message)) { if (!isset($message['ts'])) { $message['ts'] = time(); } if (!isset($message['client_ip'])) { $message['client_ip'] = Utils::get_client_ip(); } if (!isset($message['user_id']) && Auth::is_logged()) { $message['user_id'] = Auth::get_user_id(); } if (!isset($message['user_name']) && Auth::is_logged()) { $message['user_name'] = Auth::get_user_name(); } $oauth_client_id = Auth::get_oauth_client_id(); if (!isset($message['oauth_client_id']) && !empty($oauth_client_id)) { $message['oauth_client_id'] = $oauth_client_id; } } $message = json_encode($message); } try { $log_entry = new \LogEntry(array('category' => $category, 'message' => $message)); $messages = array($log_entry); $socket = new \TSocket(SCRIBE_HOST, SCRIBE_PORT, FALSE); $transport = new \TFramedTransport($socket); $protocol = new \TBinaryProtocolAccelerated($transport, FALSE, FALSE); $client = new \scribeClient($protocol, $protocol); $transport->open(); $client->send_log($messages); $transport->close(); } catch (\TException $e) { return FALSE; } return TRUE; }
private function connect_to_thrudex() { //Thrudex connection $socket = new TSocket('localhost', THRUDEX_PORT); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $this->thrudex = new ThrudexClient($protocol); $transport->open(); $this->thrudex->admin("create_index", THRUDEX_INDEX); }
//数据库文件 include_once '../DB/MyDB.class.php'; ERROR_REPORTING(E_ALL); INI_SET('DISPLAY_ERRORS', 'ON'); $socket = new TSocket('hive.corp.xx.com', 13080); $socket->setDebug(TRUE); // 设置接收超时(毫秒) $socket->setSendTimeout(10000); $socket->setRecvTimeout(30 * 60 * 1000); //接受时间设置为30分钟 //$transport = new TBufferedTransport($socket, 1024, 1024); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $client = new HiveClient($protocol); try { $transport->open(); } catch (TException $tx) { echo $tx->getMessage(); exit; } $yesterday = date("Y-m-d", strtotime("-1 day")); $sqlArr = array("total" => "select count(*), count(distinct uuid) from xxx where dt = '{$yesterday}' and gjch regexp '[^@]*/detail';", "category" => "select regexp_extract(gjch, '^/([^/]+)', 1), count(*), count(distinct uuid) from xxx where dt = '{$yesterday}' and gjch regexp '[^@]*/detail' GROUP BY regexp_extract(gjch, '^/([^/]+)', 1);"); foreach ($sqlArr as $key => $value) { //echo $key .":" . $value ."\n"; //向hadoop提交任务,如果失败重新提交 $num = 50; while ($num > 0) { try { $taskId = $client->submitTask('*****@*****.**', 'web', $value); //echo "taskid:" . $taskId . "\n"; if ($taskId <= 0) {
function scribe_Log_test($messages) { if (!isset($GLOBALS['SCRIBE']['SCRIBE_CLIENT_TEST'])) { try { // Set up the socket connections $scribe_servers = array('localhost'); $scribe_ports = array(1463); print "creating socket pool\n"; $sock = new TSocketPool($scribe_servers, $scribe_ports); $sock->setDebug(0); $sock->setSendTimeout(100); $sock->setRecvTimeout(250); $sock->setNumRetries(1); $sock->setRandomize(false); $sock->setAlwaysTryLast(true); $trans = new TFramedTransport($sock); $prot = new TBinaryProtocol($trans); // Create the client print "creating scribe client\n"; $scribe_client = new scribeClient($prot); // Open the transport (we rely on PHP to close it at script termination) print "opening transport\n"; $trans->open(); // save it for future calls $GLOBALS['SCRIBE']['SCRIBE_CLIENT_TEST'] = $scribe_client; } catch (Exception $x) { print "Unable to create global scribe client, received exception: {$x} \n"; return; } } else { print "using existing scribe client\n"; $scribe_client = $GLOBALS['SCRIBE']['SCRIBE_CLIENT_TEST']; } try { print "sending messages\n"; $result = $scribe_client->Log($messages); if ($result != OK) { print "Warning: Log returned {$result} \n"; } return $result; } catch (Exception $x) { print "Scribe client failed logging " . count($messages) . " messages with exception: {$x} \n"; } }
function create_scribe_client() { try { // Set up the socket connections $scribe_servers = array('localhost'); $scribe_ports = array(1463); print "creating socket pool\n"; $sock = new TSocketPool($scribe_servers, $scribe_ports); $sock->setDebug(0); $sock->setSendTimeout(1000); $sock->setRecvTimeout(2500); $sock->setNumRetries(1); $sock->setRandomize(false); $sock->setAlwaysTryLast(true); $trans = new TFramedTransport($sock); $prot = new TBinaryProtocol($trans); // Create the client print "creating scribe client\n"; $scribe_client = new scribeClient($prot); // Open the transport (we rely on PHP to close it at script termination) print "opening transport\n"; $trans->open(); } catch (Exception $x) { print "Unable to create global scribe client, received exception: {$x} \n"; return null; } return $scribe_client; }
/** * Contact the bounce timer server. */ public static function doBounceQuery($query) { global $IP, $THRIFT_ROOT; $THRIFT_ROOT = "{$IP}/extensions/wikihow/common/thrift"; require_once $THRIFT_ROOT . '/Thrift.php'; require_once $THRIFT_ROOT . '/protocol/TBinaryProtocol.php'; require_once $THRIFT_ROOT . '/transport/TSocket.php'; require_once $THRIFT_ROOT . '/transport/TFramedTransport.php'; require_once $THRIFT_ROOT . '/packages/BounceTimer/btLogProxy.php'; require_once $THRIFT_ROOT . '/packages/BounceTimer/btLogServer.php'; require_once $THRIFT_ROOT . '/packages/BounceTimer/BounceTimer_types.php'; try { $socket = new TSocket(WH_BOUNCETIMER_SERVER, WH_BOUNCETIMER_PORT); $transport = new TFramedTransport($socket, 1024, 1024); $protocol = new TBinaryProtocol($transport); $client = new btLogServerClient($protocol); $transport->open(); $results = $client->query(json_encode($query)); $out = array('err' => '', 'results' => json_decode($results, true)); $transport->close(); } catch (TException $e) { $err = $e->getMessage() . "\n" . print_r(debug_backtrace(), true); $out = array('err' => $err); } return $out; }
private static function logToScribe($messages) { global $THRIFT_ROOT; require_once $THRIFT_ROOT . '/Thrift.php'; require_once $THRIFT_ROOT . '/transport/TSocket.php'; require_once $THRIFT_ROOT . '/transport/TFramedTransport.php'; require_once $THRIFT_ROOT . '/protocol/TBinaryProtocol.php'; require_once 'Scribe.php'; $entries = array(); foreach ($messages as $message) { $entries[] = new LogEntry($message); } $socket = new TSocket(Z_CONFIG::$LOG_ADDRESS, Z_CONFIG::$LOG_PORT, true); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport, false, false); $scribe = new scribeClient($protocol, $protocol); $transport->open(); $scribe->Log($entries); $transport->close(); }
public function logMulti(array $messages) { $this->_transport->open(); $this->_client->Log($messages); $this->_transport->close(); }