/** * Show a list of all store sessions */ public function show_log() { if (!$this->db_adapter) { throw new RuntimeException('A DB adapter must be configured to read the stored profiler sessions'); } if (isset($_REQUEST['show']) && is_numeric($_REQUEST['show'])) { $session_id = $_REQUEST['show']; $session_meta = $this->db_adapter->query("SELECT * FROM {$this->_table} WHERE id={$session_id}"); $session_meta = $session_meta[0]; $session = unserialize(gzdecode(base64_decode($session_meta['data']))); } else { if (isset($_REQUEST['remove'])) { $session_id = $_REQUEST['remove']; if ($session_id == 'all') { $this->db_adapter->query("TRUNCATE {$this->_table}"); } elseif (is_numeric($session_id)) { $this->db_adapter->query("DELETE FROM {$this->_table} WHERE id={$session_id}"); } } $offset = isset($_REQUEST['offset']) && is_numeric($_REQUEST['offset']) ? $_REQUEST['offset'] : 0; $per_page = isset($_REQUEST['count']) && is_numeric($_REQUEST['count']) ? $_REQUEST['count'] : 25; $sessions = $this->db_adapter->query("SELECT * FROM {$this->_table} ORDER BY date DESC LIMIT {$offset},{$per_page}"); $total = $this->db_adapter->query("SELECT COUNT(*) AS c FROM {$this->_table}"); $total = $total[0]['c']; } require 'templates/Log.php'; }
/** * Ends the current session, gathering all the available environment data */ public function gather_data($response = '', EurekaProfiler_DB_Adapter $db_adapter = null) { $this->duration = microtime(true) - $this->start; //Request data $this->url = EurekaProfiler_Tools::current_url(); $this->client_ip = EurekaProfiler_Tools::client_ip(); $this->user_agent = $_SERVER['HTTP_USER_AGENT']; $this->get_data = $_GET; $this->post_data = $_POST; $this->cookies = $_COOKIE; if (function_exists('getallheaders')) { $this->request_headers = getallheaders(); } else { $this->request_headers = array(); foreach ($_SERVER as $key => $val) { $extra_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH'); if (strpos($key, 'HTTP_') === 0 || in_array($key, $extra_headers)) { $name = str_replace(array('HTTP_', '_'), array('', '-'), $key); $this->request_headers[$name] = $val; } } } $this->request_headers = array_change_key_case($this->request_headers, CASE_UPPER); //Response data $this->response = $response; $this->response_headers = array(); if (function_exists('apache_response_headers')) { $this->response_headers += apache_response_headers(); } foreach (headers_list() as $header) { list($name, $value) = explode(':', $header, 2); $this->response_headers[$name] = trim($value); } //Runtime data $this->memory_limit = ini_get('memory_limit'); $this->memory_used = memory_get_peak_usage(true); $this->max_execution_time = ini_get('max_execution_time'); //Included files $files = get_included_files(); foreach ($files as $file) { $this->loaded_files[] = new EurekaProfiler_Included(EurekaProfiler_Tools::clean_path($file), filesize($file)); } //Explain queries if (isset($db_adapter)) { foreach ($this->events_of_type('db') as $query) { if (stripos($query->query, 'SELECT') === 0) { $query->explain = $db_adapter->first_row("EXPLAIN {$query->query}"); } else { $query->explain = false; } } } }