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); }
/** * Constructor. * * @param TTransport $transport Underlying transport */ public function __construct($transport = null, $protocols = null) { parent::__construct($transport, true, true); if ($protocols) { foreach ($protocols as $protocol) { $this->supportedProtocols[$protocol] = true; } } }
public function __construct($transport = null, $protocols = null) { parent::__construct($transport, true, true); $this->readTrans_ = new \HH\Vector(array()); $this->writeTrans_ = new \HH\Vector(array()); $this->readHeaders = \HH\Map::hacklib_new(array(), array()); $this->writeHeaders = \HH\Map::hacklib_new(array(), array()); $this->persistentWriteHeaders = \HH\Map::hacklib_new(array(), array()); $this->supportedProtocols = new \HH\Set(array(self::HEADER_CLIENT_TYPE, self::FRAMED_DEPRECATED, self::UNFRAMED_DEPRECATED, self::HTTP_CLIENT_TYPE)); if (\hacklib_cast_as_boolean($protocols)) { $this->supportedProtocols->addAll($protocols); } }
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TFramedTransport.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php'; //生成的文件 require_once dirname(__FILE__) . '/Hive.php'; //数据库文件 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) {
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; }
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}/transport/TMemoryBuffer.php"; # Thrudoc error_reporting(E_NONE); $GEN_DIR = realpath(dirname(__FILE__) . '/../gen-php'); require_once "{$GEN_DIR}/Thrudoc.php"; require_once "{$GEN_DIR}/Thrudoc_types.php"; error_reporting(E_ALL); $THRUDOC_PORT = 11291; $THRUDOC_BUCKET = 'foo'; # Connect try { $socket = new TSocket('localhost', $THRUDOC_PORT); $transport = new TFramedTransport($socket); $protocol = new TBinaryProtocol($transport); $thrudoc = new ThrudocClient($protocol); $transport->open(); } catch (Exception $e) { echo "connect failed:\n{$e}\n"; } # Get (and fail) try { echo $thrudoc->get($THRUDOC_BUCKET, 'foo'), "\n"; } catch (Thrudoc_ThrudocException $e) { echo "Get 1 failed (expected):\n{$e}\n"; } # Put try { echo $thrudoc->put($THRUDOC_BUCKET, 'foo', 'bar'), "\n";
/** * 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(); }