public static function handleError($errno, $errstr, $errfile, $errline) { $errorType = array(E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE', E_STRICT => 'STRICT NOTICE', E_RECOVERABLE_ERROR => 'RECOVERABLE ERROR'); logStd('APPLICATION ERROR', 'Error Type: ' . $errorType[$errno] . "\r\n" . 'Error Message : ' . $errstr . "\r\n" . 'Error File : ' . $errfile . "\r\n" . 'Error Line : ' . $errline . "\r\n"); if (!defined('ERROR')) { define('ERROR', true); } }
/** * Gets the specified database adapter from the pool.<br> * This method ensures that a random active adapter is made available. * If no slave adapters are found, the default master adapter will be used. * If no master adapters are found, an error will be thrown. * * @var $type the type of connection required: master|slave * @return Zend_Db_Adapter_Abstract * @author Tim Woo <*****@*****.**> */ private static function _getAdapterFromPool($type = 'master') { // Get server pool from the registry $registry = Zend_Registry::getInstance(); $servers = $registry->get($type . '_servers'); // Pick a random connection until we have an active connection $unconnected = true; $attempts = array(); do { $id = rand(1, sizeof($servers)); if ($servers[$id] != null) { $db = $servers[$id]; $db->getConnection(); //$this->_db = $servers[$id]; //$this->_db->getConnection(); //$this->setDefaultAdapter($this->_db); $unconnected = false; logStd('db', 'Connected to ' . $type . ': ' . $id . ' of ' . sizeof($servers)); } else { if (array_key_exists($id, $attempts)) { logStd('db', 'Skipping failed connection to ' . $type . ': ' . $id . ' of ' . sizeof($servers)); } else { $attempts[$id] = $id; logStd('db', 'Connection failed to ' . $type . ': ' . $id . ' of ' . sizeof($servers)); $id = null; } } } while ($unconnected && sizeof($attempts) < sizeof($servers)); //ensure we don't loop forever //return $id; return $db; }
/** * Query Solr. Provide the core to search, a starting offset * for result documents, and the maximum number of result * documents to return. */ public function select($coreName, $query = '', $fields = '', $offset = 0, $limit = 10, $exact = false, $sort = '', $solrParams = array()) { $startTime = microtime(true); $returnResponse = null; $version = '2.2'; $indent = 'on'; $queryType = 'standard'; // construct the params for Solr $solrQuery = array($query); $solrPath = '/solr/' . $coreName; $solrParams['start'] = $offset; $solrParams['rows'] = $limit; $solrParams['indent'] = $indent; if ($sort) { $solrParams['sort'] = $sort; } $solrParams['fl'] = $fields; if ($exact) { $solrParams['qt'] = $queryType; } $startTime1 = microtime(true); // get memcache instance $registry = Zend_Registry::getInstance(); $memcache = $registry->get('MEMCACHE'); $solrUseCache = $registry->get('CONFIG')->solr->usecache; // get id of query $id = $this->makeId($coreName, $query, $solrParams); // try to get the solrQuery from memcached first if ($solrUseCache) { $store = 'MEMCACHED'; $returnResponse = $memcache->load($id); try { // [tim] Retrieve object from memcache and ungzip // [tim] only unzip if response is a string if (is_string($returnResponse)) { $returnResponse = unserialize(gzinflate($returnResponse)); } } catch (Exception $e) { logError('Solr could not inflate object from memcache ', $e); // Force retrieval from Solr further down $returnResponse = null; } } else { $memcache->remove($id); // clear cache entry to force to go to Solr } if (!$returnResponse) { try { $response = $this->solrBalancer->search($solrPath, $solrQuery, $offset, $limit, $solrParams); if ($response->getHttpStatus() == 200) { // store docs in cache $returnResponse = $response->response; $startTime1 = microtime(true); // [tim] Store object in memcache using gzip to get around the 1Mb memcache limit $memcache->save(gzdeflate(serialize($returnResponse)), $id); } else { logError('Solr http status msg: ', $response->getHttpStatusMessage()); } $store = 'SOLR'; } catch (Exception $e) { logError('Solr server fatal error ', $e); throw new Exception('Solr Server fatal exception'); } } $size = mb_strlen(serialize($returnResponse), '8bit'); $numFound = isset($returnResponse->numFound) ? $returnResponse->numFound : 0; $this->selectTime = microtime(true) - $startTime; $logString = '[core: ' . $coreName . '] '; $logString .= '[query: ' . $query . '] '; $logString .= '[sort: ' . $sort . '] '; $logString .= '[found: ' . $numFound . '] '; $logString .= '[store: ' . $store . '] '; $logString .= '[size: ' . $size . '] '; $logString .= '[time: ' . sprintf("%.2f", $this->selectTime) . ' secs]'; logStd('SolrServer', $logString); return $returnResponse; }
function logRoute($function, $controller) { logStd($function, $controller->getFrontController()->getRouter()->getCurrentRouteName()); }
public function query($sql, $bind = array()) { logStd('query', 'using customer pgsql adapter'); return parent::query($sql, $bind); }
public function fetchAllMaster($where = null, $order = null, $count = null, $offset = null) { $this->_db = CrFramework_Db_Control::getMasterAdapter(); $this->setDefaultAdapter($this->_db); logStd(get_class($this) . '->fetchAll()', 'Read from MASTER'); $rowset = parent::fetchAll($where, $order, $count, $offset); return $rowset; }