Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Description of DDBCallLog
  5. *
  6. * @author fsocca
  7. */
  8.  
  9. if(APP_NAME_CONSTANT == 'payback')
  10. {
  11. require_once($_SERVER['DOCUMENT_ROOT']."/rest/v1/db_c.php");
  12. }
  13. else {
  14. require_once($_SERVER['DOCUMENT_ROOT']."/newcore/php/db_c.php");
  15. }
  16.  
  17. class DDBCallLog
  18. {
  19. private static $instance = null;
  20.  
  21. private function __construct() {
  22. }
  23.  
  24. public function __destruct() {
  25. self::close();
  26. }
  27.  
  28. //////////////////////////////////////////////////////////
  29. public static function getInstance(){
  30. if(!self::$instance instanceof self){
  31. self::$instance = new self;
  32. }
  33. return(self::$instance);
  34. }
  35.  
  36. //////////////////////////////////////////////////////////
  37. public function log($op_type, $cardinality, $consistency, $key, $value_len, $op_duration = null)
  38. {
  39. $history = debug_backtrace();
  40.  
  41. $caller_file = $history[1]['file'];
  42. $caller_line = $history[1]['line'];
  43.  
  44. $query = 'INSERT INTO `mcache_log` (`op_type`,`cardinality`,`consistency`,`caller_file`,`caller_line`,`key_`,`value_len`,`op_duration`) VALUES ' .
  45. "('$op_type', '$cardinality', '$consistency', '$caller_file', $caller_line, '$key', $value_len, $op_duration)";
  46.  
  47. if ($s = db_c::query($query)) {
  48. return true;
  49. } else {
  50. $ddl = "CREATE TABLE IF NOT EXISTS `mcache_log` (" .
  51. "`id` int(11) NOT NULL AUTO_INCREMENT," .
  52. "`op_type` char(1) NOT NULL," .
  53. "`cardinality` char(1) DEFAULT NULL," .
  54. "`consistency` char(1) DEFAULT NULL," .
  55. "`caller_file` varchar(255) DEFAULT NULL," .
  56. "`caller_line` mediumint(9) DEFAULT NULL," .
  57. "`key_` varchar(255) NOT NULL," .
  58. "`value_len` int(11) DEFAULT NULL," .
  59. "`op_duration` float DEFAULT NULL," .
  60. "`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP," .
  61. "PRIMARY KEY (`id`)" .
  62. ") ENGINE=InnoDB DEFAULT CHARSET=latin1;";
  63.  
  64. if($s = db_c::query($ddl)) {
  65. if ($s = db_c::query($query)) {
  66. return true;
  67. } else {
  68. error_log(__METHOD__ . ' (' . __LINE__ . ') Warning: Could not log MemcachedHandler key access.');
  69. return false;
  70. }
  71. } else {
  72. error_log(__METHOD__ . ' (' . __LINE__ . ') Warning: Could not log MemcachedHandler key access.');
  73. return false;
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement