Beispiel #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;
 }
 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";
     }
 }
            echo "Deleting {$ip} from list {$listName}/{$listType}\n";
        }
        $client->deleteAllRow("hogzilla_reputation", $row[0]->row, array());
    }
    $client->scannerClose($scanner);
    // Iterate file
    while (($ip = fgets($fileHandle)) !== false) {
        // Parse
        preg_replace("/\r|\n/", "", $ip);
        $ip = trim($ip);
        // Create mutation
        $mutations = array();
        $dataIP = array('column' => "rep:ip", 'value' => $ip);
        $dataListName = array('column' => "rep:list", 'value' => $listName);
        $dataListType = array('column' => "rep:list_type", 'value' => $listType);
        $dataListDesc = array('column' => "rep:description", 'value' => "");
        $mutations[] = new Hbase\Mutation($dataIP);
        $mutations[] = new Hbase\Mutation($dataListName);
        $mutations[] = new Hbase\Mutation($dataListType);
        $mutations[] = new Hbase\Mutation($dataListDesc);
        // Insert mutations
        $client->mutateRow("hogzilla_reputation", $ip . "-" . $listName . "-" . $listType, $mutations, array());
    }
} catch (Exception $e) {
    echo 'ERROR: ', $e->getMessage(), "\n";
}
// Close file
fclose($fileHandle);
// Close connections (HBase)
$transport->close();