Пример #1
0
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;
}
Пример #2
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";
    }
}
 /**
  * Create connector object
  * @param array $config
  * @return TTransport
  */
 private static function getConnector($config)
 {
     $class = isset($config['class']) ? $config['class'] : '';
     $param = isset($config['param']) ? $config['param'] : array();
     switch ($class) {
         case 'THttpClient':
             if (!isset($param['host'])) {
                 throw new Exception('Bad Thrift transport config');
             }
             $host = $param['host'];
             $port = isset($param['port']) ? $param['port'] : 80;
             $uri = isset($param['uri']) ? $param['uri'] : '';
             $scheme = isset($param['scheme']) ? $param['scheme'] : 'http';
             $timeout = isset($param['timeout']) ? $param['timeout'] : null;
             $connector = new THttpClient($url, $port, $uri, $scheme);
             $connector->setTimeoutSecs($timeout);
             $parameters = sprintf('host = "%s", port = %d, uri = "%s", scheme = "%s", timeout = %d', $host, $port, $uri, $scheme, $timeout);
             break;
         case 'TMemoryBuffer':
             $buf = isset($param['buf']) ? $param['buf'] : '';
             $connector = new TMemoryBuffer($buf);
             $parameters = sprintf('buf = "%s"', $buf);
             break;
         case 'TPhpStream':
             if (!isset($param['mode'])) {
                 throw new Exception('Bad Thrift transport config');
             }
             $mode = $param['mode'];
             $connector = new TPhpStream($mode);
             $parameters = sprintf('mode = %d', $mode);
             break;
         case 'TSocket':
             $host = isset($param['host']) ? $param['host'] : 'localhost';
             $port = isset($param['port']) ? $param['port'] : 9090;
             $persist = isset($param['persist']) ? $param['persist'] : false;
             $send_timeout = isset($param['send_timeout']) ? $param['send_timeout'] : 100;
             $recv_timeout = isset($param['recv_timeout']) ? $param['recv_timeout'] : 750;
             $connector = new TSocket($host, $port, $persist);
             $connector->setSendTimeout($send_timeout);
             $connector->setRecvTimeout($recv_timeout);
             $parameters = sprintf('host = "%s", port = %d, persist = %s, send_timeout = %d, recv_timeout = %d', $host, $port, $persist ? 'true' : 'false', $send_timeout, $recv_timeout);
             break;
         case 'TSocketPool':
             $hosts = isset($param['hosts']) ? $param['hosts'] : array('localhost');
             $ports = isset($param['ports']) ? $param['ports'] : array(9090);
             $persist = isset($param['persist']) ? $param['persist'] : false;
             $send_timeout = isset($param['send_timeout']) ? $param['send_timeout'] : 100;
             $recv_timeout = isset($param['recv_timeout']) ? $param['recv_timeout'] : 750;
             $connector = new TSocketPool($hosts, $ports, $persist);
             $connector->setSendTimeout($send_timeout);
             $connector->setRecvTimeout($recv_timeout);
             $parameters = sprintf('hosts = ("%s"), ports = (%d), persist = %s, send_timeout = %d, recv_timeout = %d', implode('","', $hosts), implode('","', $ports), $persist ? 'true' : 'false', $send_timeout, $recv_timeout);
             break;
         default:
             throw new Exception('Unknown connector: ' . $class);
     }
     sfContext::getInstance()->getLogger()->info(sprintf('{sfThriftPlugin}Create %s connector with parameters: %s', $class, $parameters));
     return $connector;
 }