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
    exit;
}
// Open file
if (DEBUG) {
    echo "Open file\n";
}
$fileHandle = fopen($listFile, "r");
if (!$fileHandle) {
    echo "Error opening file {$listFile} .";
    exit;
}
// Open connections
if (DEBUG) {
    echo "Open connection\n";
}
$transport->open();
// Scan+Filter on HBase
$filter = array();
$filter[] = "SingleColumnValueFilter('rep', 'list_type', =, 'binary:" . $listType . "')";
$filter[] = "SingleColumnValueFilter('rep', 'list',      =, 'binary:" . $listName . "')";
$filterString = implode(" AND ", $filter);
$scanFilter = new Hbase\TScan();
$scanFilter->filterString = $filterString;
$scanner = $client->scannerOpenWithScan("hogzilla_reputation", $scanFilter, array());
// Delete rows, iterating
if (DEBUG) {
    echo "Deleting current list from HBase\n";
}
try {
    while (true) {
        $row = $client->scannerGet($scanner);