Beispiel #1
0
 /**
  * Save the run in the database. 
  * 
  * @param string $xhprof_data
  * @param mixed $type
  * @param string $run_id
  * @param mixed $xhprof_details
  * @return string
  */
 public function save_run($xhprof_data, $type, $run_id = null, $xhprof_details = null)
 {
     global $_xhprof;
     $sql = array();
     if ($run_id === null) {
         $run_id = $this->gen_run_id($type);
     }
     /*
     		Session data is ommitted purposefully, mostly because it's not likely that the data
     		that resides in $_SESSION at this point is the same as the data that the application
     		started off with (for most apps, it's likely that session data is manipulated on most
     		pageloads).
     The goal of storing get, post and cookie is to help explain why an application chose
     		a particular code execution path, pehaps it was a poorly filled out form, or a cookie that
     		overwrote some default parameters. So having them helps. Most applications don't push data
     		back into those super globals, so we're safe(ish) storing them now. 
     We can't just clone the session data in header.php to be sneaky either, starting the session
     		is an application decision, and we don't want to go starting sessions where none are needed
     		(not good performance wise). We could be extra sneaky and do something like:
     		if(isset($_COOKIE['phpsessid']))
     		{
     			session_start();
     			$_xhprof['session_data'] = $_SESSION;
     		} 
     		but starting session support really feels like an application level decision, not one that
     		a supposedly unobtrusive profiler makes for you. 
     */
     $sql['get'] = addslashes(serialize($_GET));
     $sql['cookie'] = addslashes(serialize($_COOKIE));
     //This code has not been tested
     if ($_xhprof['savepost']) {
         $sql['post'] = addslashes(serialize($_POST));
     } else {
         $sql['post'] = addslashes(serialize(array("Skipped" => "Post data omitted by rule")));
     }
     $sql['pmu'] = isset($xhprof_data['main()']['pmu']) ? $xhprof_data['main()']['pmu'] : '';
     $sql['wt'] = isset($xhprof_data['main()']['wt']) ? $xhprof_data['main()']['wt'] : '';
     $sql['cpu'] = isset($xhprof_data['main()']['cpu']) ? $xhprof_data['main()']['cpu'] : '';
     // The value of 2 seems to be light enugh that we're not killing the server, but still gives us lots of breathing room on
     // full production code.
     $sql['data'] = gzcompress(serialize($xhprof_data), 2);
     $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
     $sname = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
     $sql['url'] = $url;
     $sql['c_url'] = _urlSimilartor($_SERVER['REQUEST_URI']);
     $sql['servername'] = $sname;
     $sql['type'] = (int) (isset($xhprof_details['type']) ? $xhprof_details['type'] : 0);
     $sql['timestamp'] = addslashes(date('c', $_SERVER['REQUEST_TIME']));
     $sql['server_id'] = addslashes($_xhprof['servername']);
     $sql['aggregateCalls_include'] = getenv('xhprof_aggregateCalls_include') ? getenv('xhprof_aggregateCalls_include') : '';
     $query = "INSERT INTO [details] ([id], [url], [c_url], [timestamp], [server name], [perfdata], [type], [cookie], [post], [get], [pmu], [wt], [cpu], [server_id], [aggregateCalls_include]) \n        VALUES(?, ?, ?, ?, ?,?, ?, ?, ?, ?,?,?,?,?)";
     $params = array(&$run_id, &$sql['url'], &$sql['c_url'], &$sql['timestamp'], &$sql['servername'], &$sql['data'], &$sql['type'], &$sql['cookie'], &$sql['post'], &$sql['get'], &$sql['pmu'], &$sql['wt'], &$sql['cpu'], &$sql['server_id'], &$sql['aggregateCalls_include']);
     $stmt = sqlsrv_prepare($this->linkID, $query, $params);
     if ($stmt) {
         sqlsrv_execute($stmt);
         return $run_id;
     } else {
         global $_xhprof;
         if ($_xhprof['display'] === true) {
             echo "Failed to insert: {$query} <br>\n";
             var_dump(sqlsrv_errors());
         }
         return -1;
     }
 }
 /**
  * Save the run in the database. 
  * 
  * @param string $xhprof_data
  * @param mixed $type
  * @param string $run_id
  * @param mixed $xhprof_details
  * @return string
  */
 public function save_run($xhprof_data, $type, $run_id = null, $xhprof_details = null)
 {
     global $_xhprof;
     $sql = array();
     if ($run_id === null) {
         $run_id = $this->gen_run_id($type);
     }
     /*
     		Session data is ommitted purposefully, mostly because it's not likely that the data
     		that resides in $_SESSION at this point is the same as the data that the application
     		started off with (for most apps, it's likely that session data is manipulated on most
     		pageloads).
     The goal of storing get, post and cookie is to help explain why an application chose
     		a particular code execution path, pehaps it was a poorly filled out form, or a cookie that
     		overwrote some default parameters. So having them helps. Most applications don't push data
     		back into those super globals, so we're safe(ish) storing them now. 
     We can't just clone the session data in header.php to be sneaky either, starting the session
     		is an application decision, and we don't want to go starting sessions where none are needed
     		(not good performance wise). We could be extra sneaky and do something like:
     		if(isset($_COOKIE['phpsessid']))
     		{
     			session_start();
     			$_xhprof['session_data'] = $_SESSION;
     		} 
     		but starting session support really feels like an application level decision, not one that
     		a supposedly unobtrusive profiler makes for you. 
     */
     if (!isset($GLOBALS['_xhprof']['serializer']) || strtolower($GLOBALS['_xhprof']['serializer'] == 'php')) {
         $sql['get'] = mysqli_real_escape_string($this->linkID, serialize($_GET));
         $sql['cookie'] = mysqli_real_escape_string($this->linkID, serialize($_COOKIE));
         //This code has not been tested
         if ($_xhprof['savepost']) {
             $sql['post'] = mysqli_real_escape_string($this->linkID, serialize($_POST));
         } else {
             $sql['post'] = mysqli_real_escape_string($this->linkID, serialize(array("Skipped" => "Post data omitted by rule")));
         }
     } else {
         $sql['get'] = mysqli_real_escape_string($this->linkID, json_encode($_GET));
         $sql['cookie'] = mysqli_real_escape_string($this->linkID, json_encode($_COOKIE));
         //This code has not been tested
         if ($_xhprof['savepost']) {
             $sql['post'] = mysqli_real_escape_string($this->linkID, json_encode($_POST));
         } else {
             $sql['post'] = mysqli_real_escape_string($this->linkID, json_encode(array("Skipped" => "Post data omitted by rule")));
         }
     }
     $sql['pmu'] = isset($xhprof_data['main()']['pmu']) ? $xhprof_data['main()']['pmu'] : '';
     $sql['wt'] = isset($xhprof_data['main()']['wt']) ? $xhprof_data['main()']['wt'] : '';
     $sql['cpu'] = isset($xhprof_data['main()']['cpu']) ? $xhprof_data['main()']['cpu'] : '';
     // The value of 2 seems to be light enugh that we're not killing the server, but still gives us lots of breathing room on
     // full production code.
     if (!isset($GLOBALS['_xhprof']['serializer']) || strtolower($GLOBALS['_xhprof']['serializer'] == 'php')) {
         $sql['data'] = mysqli_real_escape_string($this->linkID, gzcompress(serialize($xhprof_data), 2));
     } else {
         $sql['data'] = mysqli_real_escape_string($this->linkID, gzcompress(json_encode($xhprof_data), 2));
     }
     $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
     $sname = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
     $sql['url'] = mysqli_real_escape_string($this->linkID, $url);
     $sql['c_url'] = mysqli_real_escape_string($this->linkID, _urlSimilartor($url));
     $sql['servername'] = mysqli_real_escape_string($this->linkID, $sname);
     $sql['type'] = (int) (isset($xhprof_details['type']) ? $xhprof_details['type'] : 0);
     $sql['timestamp'] = mysqli_real_escape_string($this->linkID, $_SERVER['REQUEST_TIME']);
     $sql['server_id'] = mysqli_real_escape_string($this->linkID, $_xhprof['servername']);
     $sql['aggregateCalls_include'] = getenv('xhprof_aggregateCalls_include') ? getenv('xhprof_aggregateCalls_include') : '';
     $query = "INSERT INTO `details` (`id`, `url`, `c_url`, `timestamp`, `server name`, `perfdata`, `type`, `cookie`, `post`, `get`, `pmu`, `wt`, `cpu`, `server_id`, `aggregateCalls_include`) VALUES('{$run_id}', '{$sql['url']}', '{$sql['c_url']}', FROM_UNIXTIME('{$sql['timestamp']}'), '{$sql['servername']}', '{$sql['data']}', '{$sql['type']}', '{$sql['cookie']}', '{$sql['post']}', '{$sql['get']}', '{$sql['pmu']}', '{$sql['wt']}', '{$sql['cpu']}', '{$sql['server_id']}', '{$sql['aggregateCalls_include']}')";
     mysqli_query($this->linkID, $query);
     if (mysqli_affected_rows($this->linkID) == 1) {
         return $run_id;
     } else {
         global $_xhprof;
         if ($_xhprof['display'] === true) {
             echo "Failed to insert: {$query} <br>\n";
         }
         return -1;
     }
 }
 /**
  * Save the run in the database. 
  * 
  * @param string $xhprof_data
  * @param mixed $type
  * @param string $run_id
  * @param mixed $xhprof_details
  * @return string
  */
 public function save_run($xhprof_data, $type, $run_id = null, $xhprof_details = null)
 {
     global $_xhprof;
     $sql = array();
     if ($run_id === null) {
         $run_id = $this->gen_run_id($type);
     }
     /*
     		Session data is ommitted purposefully, mostly because it's not likely that the data
     		that resides in $_SESSION at this point is the same as the data that the application
     		started off with (for most apps, it's likely that session data is manipulated on most
     		pageloads).
     The goal of storing get, post and cookie is to help explain why an application chose
     		a particular code execution path, pehaps it was a poorly filled out form, or a cookie that
     		overwrote some default parameters. So having them helps. Most applications don't push data
     		back into those super globals, so we're safe(ish) storing them now. 
     We can't just clone the session data in header.php to be sneaky either, starting the session
     		is an application decision, and we don't want to go starting sessions where none are needed
     		(not good performance wise). We could be extra sneaky and do something like:
     		if(isset($_COOKIE['phpsessid']))
     		{
     			session_start();
     			$_xhprof['session_data'] = $_SESSION;
     		} 
     		but starting session support really feels like an application level decision, not one that
     		a supposedly unobtrusive profiler makes for you. 
     */
     if (!isset($GLOBALS['_xhprof']['serializer']) || strtolower($GLOBALS['_xhprof']['serializer'] == 'php')) {
         $sql['get'] = $this->db->escape(serialize($_GET));
         $sql['cookie'] = $this->db->escape(serialize($_COOKIE));
         //This code has not been tested
         if (isset($_xhprof['savepost']) && $_xhprof['savepost']) {
             $sql['post'] = $this->db->escape(serialize($_POST));
         } else {
             $sql['post'] = $this->db->escape(serialize(array("Skipped" => "Post data omitted by rule")));
         }
     } else {
         $sql['get'] = $this->db->escape(json_encode($_GET));
         $sql['cookie'] = $this->db->escape(json_encode($_COOKIE));
         //This code has not been tested
         if (isset($_xhprof['savepost']) && $_xhprof['savepost']) {
             $sql['post'] = $this->db->escape(json_encode($_POST));
         } else {
             $sql['post'] = $this->db->escape(json_encode(array("Skipped" => "Post data omitted by rule")));
         }
     }
     $sql['pmu'] = isset($xhprof_data['main()']['pmu']) ? $xhprof_data['main()']['pmu'] : '';
     $sql['wt'] = isset($xhprof_data['main()']['wt']) ? $xhprof_data['main()']['wt'] : '';
     $sql['cpu'] = isset($xhprof_data['main()']['cpu']) ? $xhprof_data['main()']['cpu'] : '';
     if (!isset($GLOBALS['_xhprof']['serializer'])) {
         $serializer = 'php';
     } else {
         $serializer = $GLOBALS['_xhprof']['serializer'];
     }
     //The Performance data is compressed lightly to avoid max row length
     switch ($GLOBALS['_xhprof']['serializer']) {
         case 'php':
             $xhprof_data = serialize($xhprof_data);
             break;
         default:
         case 'json':
             $xhprof_data = json_encode($xhprof_data, true);
             break;
         case 'igbinary':
             $xhprof_data = igbinary_serialize($xhprof_data);
             break;
     }
     $xhprof_data = gzcompress($xhprof_data, 9);
     $sql['data'] = $this->db->escape($xhprof_data);
     $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
     $sname = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
     $sql['url'] = $this->db->escape($url);
     $sql['c_url'] = $this->db->escape(_urlSimilartor($_SERVER['REQUEST_URI']));
     $sql['servername'] = $this->db->escape($sname);
     $sql['type'] = (int) (isset($xhprof_details['type']) ? $xhprof_details['type'] : 0);
     $sql['timestamp'] = $this->db->escape($_SERVER['REQUEST_TIME']);
     $sql['server_id'] = $this->db->escape($_xhprof['servername']);
     $sql['aggregateCalls_include'] = getenv('xhprof_aggregateCalls_include') ? getenv('xhprof_aggregateCalls_include') : '';
     $query = "INSERT INTO system_profiler (id, url, c_url, timestamp, server_name, perfdata, type, cookie, post, get, pmu, wt, cpu, server_id, aggregateCalls_include) VALUES('{$run_id}', '{$sql['url']}', '{$sql['c_url']}', FROM_UNIXTIME('{$sql['timestamp']}'), '{$sql['servername']}', '{$sql['data']}', '{$sql['type']}', '{$sql['cookie']}', '{$sql['post']}', '{$sql['get']}', '{$sql['pmu']}', '{$sql['wt']}', '{$sql['cpu']}', '{$sql['server_id']}', '{$sql['aggregateCalls_include']}')";
     $this->db->query($query);
     if ($this->db->affectedRows($this->db->linkID) == 1) {
         return $run_id;
     } else {
         global $_xhprof;
         if ($_xhprof['display'] === true) {
             echo "Failed to insert: {$query} <br>\n";
         }
         return -1;
     }
 }