Exemplo n.º 1
0
 /**
  * request remote api service
  *
  * @param string $timeout            
  * @param string $headers            
  * @param string $uri            
  * @param string $clientClass            
  * @param string $clientMethod            
  * @param array $arguments            
  * @throws Exception
  * @return mixed
  */
 private function request($timeout = 0, array $headers = array(), $clientClass, $clientMethod, array $arguments)
 {
     if (!$this->_host) {
         $Constant = preg_replace("/[a-zA-Z0-9_]{1,}Client\$/", "Constant", $clientClass);
         $this->_host = call_user_func_array(array("{$Constant}", "get"), array("apihost"));
     }
     preg_match_all("/([A-Za-z0-9]{1,})Client\$/", $clientClass, $match);
     $urlinfo = parse_url($this->_host);
     $socket = new \Thrift\Transport\THttpClient($urlinfo['host'], isset($urlinfo['port']) ? $urlinfo['port'] : 80, $urlinfo['path'] . $match[1][0]);
     $transport = new \Thrift\Transport\TBufferedTransport($socket, 1024, 1024);
     // $protocol = new \Thrift\Protocol\TJSONProtocol($transport);
     $protocol = new \Thrift\Protocol\TBinaryProtocol($transport);
     $client = new $clientClass($protocol);
     // add request timeout
     if ($timeout > 0) {
         $socket->setTimeoutSecs($timeout);
     }
     // add request header
     if ($headers) {
         $socket->addHeaders($headers);
     }
     $transport->open();
     try {
         $result = call_user_func_array(array($client, $clientMethod), $arguments);
     } catch (\Exception $e) {
         print_r($e);
     }
     $transport->close();
     return $result;
 }
Exemplo n.º 2
0
 public function index()
 {
     $flurryhost = $this->config->item('flurry_server')["host"];
     $flurryport = $this->config->item('flurry_server')["port"];
     try {
         $socket = new \Thrift\Transport\TSocket($flurryhost, $flurryport);
         $transport = new \Thrift\Transport\TBufferedTransport($socket, 1024, 1024);
         $protocol = new \Thrift\Protocol\TBinaryProtocol($transport);
         $client = new \Bazu\Flurry\FlurryClient($protocol);
         $transport->open();
         $timer_start = microtime(TRUE);
         $data['host'] = $flurryhost;
         $data['port'] = $flurryport;
         $data['id'] = $client->get_id();
         $data['msec_taken'] = round((microtime(TRUE) - $timer_start) * 1000, 3);
         $data['workerid'] = $client->get_worker_id();
         $transport->close();
         $this->load->view('flurry', $data);
     } catch (TException $tx) {
         print 'TException: ' . $tx->getMessage() . "\n";
     }
 }
Exemplo n.º 3
0
$GLOBALS['THRIFT_ROOT'] = '/usr/share/php';
define("DEBUG", true);
// Thrift stuff
require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/ClassLoader/ThriftClassLoader.php';
$classLoader = new Thrift\ClassLoader\ThriftClassLoader();
$classLoader->registerNamespace('Thrift', $GLOBALS['THRIFT_ROOT']);
$classLoader->register();
require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Packages/Hbase/Hbase.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Packages/Hbase/Types.php';
$socket = new Thrift\Transport\TSocket($hbaseHost, $hbasePort);
$socket->setSendTimeout(10000);
$socket->setRecvTimeout(20000);
$transport = new Thrift\Transport\TBufferedTransport($socket);
$protocol = new Thrift\Protocol\TBinaryProtocol($transport);
$client = new Hbase\HbaseClient($protocol);
/*
 * BEGIN
 */
// Parse arguments
if (DEBUG) {
    echo "Parse options\n";
}
$options = getopt("t:n:f:");
$listType = @$options["t"];
$listName = @$options["n"];
$listFile = @$options["f"];
if (strlen($listType) == 0 || strlen($listName) == 0 || strlen($listFile) == 0) {
    echo "Usage: php updateReputationList.php -t ListType -n ListName -f file \n";