public function countAction() { $profile = Zend_Auth::getInstance()->getIdentity(); $user = UserTable::load($profile->getId()); $newcount = $user->getFollowStreamCount(); // make sure that we close the database handles HypertableConnection::close(); die('' . $newcount); }
public function store($tweet, $author) { if (!$tweet->getId()) $tweet->createId($author); HypertableConnection::insert('tweet', $tweet->getId(), 'message', $tweet->getMessage()); $u=UserTable::load($author); $u->sendTweet($tweet); return true; }
public function create($username) { try { $guid=HypertableConnection::create_cell_unique('profile', $username, 'guid'); $profile = new Profile(); $profile->setGuid($guid); $profile->setId($username); return $profile; } catch (Exception $e) { if($e->getCode()==48) // a cell with this username already exists return null; else throw $e; } }
public function getFollowStream($cutoff_time, $limit) { $a=array(); $id=$this->_id; if ($cutoff_time) $t="AND TIMESTAMP < '". HypertableConnection::format_timestamp_ns($cutoff_time)."' "; else $t=''; $result=HypertableConnection::query("SELECT follow_stream FROM user ". "WHERE ROW='$id' $t CELL_LIMIT $limit"); if (!$result or !count($result->cells)) return $a; foreach ($result->cells as $cell) { array_push($a, TweetTable::load($cell->value)); } $this->_cutoff=$result->cells[count($result->cells)-1]->key->timestamp; return $a; }
protected static function initialize() { $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $options = $bootstrap->getOptions(); if (!self::$_client) { $host = $options['hypertable']['thriftclient']['hostname']; $port = $options['hypertable']['thriftclient']['port']; self::$_client = new Hypertable_ThriftClient($host, $port); } if (!self::$_namespace) { $ns = $options['hypertable']['namespace']; self::$_namespace = self::$_client->open_namespace($ns); } }
<?php // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), realpath(APPLICATION_PATH . '/../application/models'), get_include_path()))); // Zend_Application require_once 'Zend/Application.php'; /** * Load Hypertable. The THRIFT_ROOT specifies the directory with the * Hypertable Thrift client. THRIFT_ROOT can be an absolute path or relative * to any directory in your include path. In our case the client is in * 'library/Hypertable', and 'library' is in the include path. * * If you do not set THRIFT_ROOT then the client will follow a heuristic * approach to find the libraries. It is recommended to set THRIFT_ROOT. */ $GLOBALS['THRIFT_ROOT'] = 'Hypertable'; require_once 'Hypertable/ThriftClient.php'; // Create application, bootstrap, and run $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $application->bootstrap()->run(); /** * Clean up the hypertable handles to avoid leaks in the ThriftBroker */ require_once 'HypertableConnection.php'; HypertableConnection::close();