Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Description of DDBCallLog
- *
- * @author fsocca
- */
- if(APP_NAME_CONSTANT == 'payback')
- {
- require_once($_SERVER['DOCUMENT_ROOT']."/rest/v1/db_c.php");
- }
- else {
- require_once($_SERVER['DOCUMENT_ROOT']."/newcore/php/db_c.php");
- }
- class DDBCallLog
- {
- private static $instance = null;
- private function __construct() {
- }
- public function __destruct() {
- self::close();
- }
- //////////////////////////////////////////////////////////
- public static function getInstance(){
- if(!self::$instance instanceof self){
- self::$instance = new self;
- }
- return(self::$instance);
- }
- //////////////////////////////////////////////////////////
- public function log($op_type, $cardinality, $consistency, $key, $value_len, $op_duration = null)
- {
- $history = debug_backtrace();
- $caller_file = $history[1]['file'];
- $caller_line = $history[1]['line'];
- $query = 'INSERT INTO `mcache_log` (`op_type`,`cardinality`,`consistency`,`caller_file`,`caller_line`,`key_`,`value_len`,`op_duration`) VALUES ' .
- "('$op_type', '$cardinality', '$consistency', '$caller_file', $caller_line, '$key', $value_len, $op_duration)";
- if ($s = db_c::query($query)) {
- return true;
- } else {
- $ddl = "CREATE TABLE IF NOT EXISTS `mcache_log` (" .
- "`id` int(11) NOT NULL AUTO_INCREMENT," .
- "`op_type` char(1) NOT NULL," .
- "`cardinality` char(1) DEFAULT NULL," .
- "`consistency` char(1) DEFAULT NULL," .
- "`caller_file` varchar(255) DEFAULT NULL," .
- "`caller_line` mediumint(9) DEFAULT NULL," .
- "`key_` varchar(255) NOT NULL," .
- "`value_len` int(11) DEFAULT NULL," .
- "`op_duration` float DEFAULT NULL," .
- "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," .
- "PRIMARY KEY (`id`)" .
- ") ENGINE=InnoDB DEFAULT CHARSET=latin1;";
- if($s = db_c::query($ddl)) {
- if ($s = db_c::query($query)) {
- return true;
- } else {
- error_log(__METHOD__ . ' (' . __LINE__ . ') Warning: Could not log MemcachedHandler key access.');
- return false;
- }
- } else {
- error_log(__METHOD__ . ' (' . __LINE__ . ') Warning: Could not log MemcachedHandler key access.');
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement