/**
  * Ends the current session, gathering all the available environment data
  *
  * @param string                    $response   HTML response for the current request
  * @param EurekaProfiler_DB_Adapter $db_adapter DB Adapter used to query the database
  * @param boolean                   $store      Store current profile data in the database
  */
 public function finish($response = '', $store = false)
 {
     $this->disable();
     //Create events tree
     $event_tree = array();
     foreach ($this->_session->events as $event) {
         $closest = null;
         //Search event that starts before and ends after current
         foreach ($this->_session->events as $sibling) {
             if ($sibling != $event && $sibling->duration > 0 && $sibling->timemark < $event->timemark && $sibling->timemark + $sibling->duration > $event->timemark + $event->duration) {
                 $closest = $sibling;
             }
         }
         if ($closest) {
             $closest->add_child($event);
         } else {
             $event_tree[] = $event;
         }
     }
     $this->_session->events = $event_tree;
     $this->_session->gather_data($response, $this->db_adapter);
     //Store session data
     if ($store) {
         if (!$this->db_adapter) {
             throw new RuntimeException('A DB adapter must be configured before storing profiler sessions');
         }
         $this->db_adapter->insert($this->_table, array('date' => $this->_session->start, 'url' => EurekaProfiler_Tools::current_url(), 'data' => base64_encode(gzencode(serialize($this->_session), 9))));
     }
 }
示例#2
0
 /**
  * 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;
             }
         }
     }
 }