public $identities;
public $is_mobile;
public $is_tablet;
-
+ public $performance = array();
+
public $nav_sel;
public $category;
private $cached_profile_image;
private $cached_profile_picdate;
-
+
function __construct() {
global $default_timezone, $argv, $argc;
date_default_timezone_set($this->timezone);
+ $this->performance["start"] = microtime(true);
+ $this->performance["database"] = 0;
+ $this->performance["network"] = 0;
+ $this->performance["rendering"] = 0;
+
$this->config = array();
$this->page = array();
$this->pager= array();
$this->error = '';
- if(x($a->config,'system') && x($a->config['system'],'db_log'))
- $stamp1 = microtime(true);
+ $stamp1 = microtime(true);
if($this->mysqli)
$result = @$this->db->query($sql);
else
$result = @mysql_query($sql,$this->db);
+ $stamp2 = microtime(true);
+ $duration = (float)($stamp2-$stamp1);
+ $a->performance["database"] += (float)$duration;
+
if(x($a->config,'system') && x($a->config['system'],'db_log')) {
- $stamp2 = microtime(true);
- $duration = round($stamp2-$stamp1, 3);
if (($duration > $a->config["system"]["db_loglimit"])) {
+ $duration = round($duration, 3);
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents($a->config["system"]["db_log"], $duration."\t".
basename($backtrace[1]["file"])."\t".
if(! function_exists('fetch_url')) {
function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) {
+ $stamp1 = microtime(true);
+
$a = get_app();
$ch = @curl_init($url);
- if(($redirects > 8) || (! $ch))
+ if(($redirects > 8) || (! $ch))
return false;
@curl_setopt($ch, CURLOPT_HEADER, true);
$body = substr($s,strlen($header));
$a->set_curl_headers($header);
@curl_close($ch);
+
+ $stamp2 = microtime(true);
+ $duration = (float)($stamp2-$stamp1);
+ $a->performance["network"] += (float)$duration;
+
return($body);
}}
if(! function_exists('post_url')) {
function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) {
+
+ $stamp1 = microtime(true);
+
$a = get_app();
$ch = curl_init($url);
if(($redirects > 8) || (! $ch))
$a->set_curl_headers($header);
curl_close($ch);
+
+ $stamp2 = microtime(true);
+ $duration = (float)($stamp2-$stamp1);
+ $a->performance["network"] += (float)$duration;
+
return($body);
}}
if($link['@attributes']['rel'] === NAMESPACE_DFRN)
$profile_link = $link['@attributes']['href'];
if($link['@attributes']['rel'] === NAMESPACE_OSTATUSSUB)
- $profile_link = 'stat:' . $link['@attributes']['template'];
+ $profile_link = 'stat:' . $link['@attributes']['template'];
if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard')
- $hcard = $link['@attributes']['href'];
+ $hcard = $link['@attributes']['href'];
}
}
return $profile_link;
elseif(x($link['@attributes'],'href'))
$href = $link['@attributes']['href'];
}
- }
+ }
}
if((! isset($tpl)) || (! strpos($tpl,'{uri}')))
$lines = explode("\n",$headers);
if(count($lines)) {
- foreach($lines as $line) {
+ foreach($lines as $line) {
if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) {
return(fetch_xrd_links($matches[1]));
break;
$lines = explode("\n",$headers);
if(count($lines)) {
- foreach($lines as $line) {
+ foreach($lines as $line) {
// TODO alter the following regex to support multiple relations (space separated)
if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) {
$pagelink = $matches[1];
if(! function_exists('validate_url')) {
function validate_url(&$url) {
-
+
// no naked subdomains (allow localhost for tests)
if(strpos($url,'.') === false && strpos($url,'/localhost/') === false)
return false;
if(substr($url,0,4) != 'http')
$url = 'http://' . $url;
$h = @parse_url($url);
-
+
if(($h) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) {
return true;
}
// returns substituted string.
// WARNING: this is pretty basic, and doesn't properly handle search strings that are substrings of each other.
// For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing,
-// depending on the order in which they were declared in the array.
+// depending on the order in which they were declared in the array.
require_once("include/template_processor.php");
require_once("include/friendica_smarty.php");
-if(! function_exists('replace_macros')) {
+if(! function_exists('replace_macros')) {
function replace_macros($s,$r) {
global $t;
-// $ts = microtime();
+ $stamp1 = microtime(true);
+
$a = get_app();
if($a->theme['template_engine'] === 'smarty3') {
}
else {
$r = $t->replace($s,$r);
-
+
$output = template_unescape($r);
}
-// $tt = microtime() - $ts;
-// $a = get_app();
-// $a->page['debug'] .= "$tt <br>\n";
+ $a = get_app();
+ $stamp2 = microtime(true);
+ $duration = (float)($stamp2-$stamp1);
+ $a->performance["rendering"] += (float)$duration;
+
return $output;
}}
$d = dirname($s);
if(file_exists("$d/$lang/$b"))
return file_get_contents("$d/$lang/$b");
-
+
$theme = current_theme();
if(file_exists("$d/theme/$theme/$b"))
return file_get_contents("$d/theme/$theme/$b");
-
+
return file_get_contents($s);
}}
if(! function_exists('get_markup_template')) {
function get_markup_template($s, $root = '') {
-// $ts = microtime();
+ $stamp1 = microtime(true);
+
$a = get_app();
if($a->theme['template_engine'] === 'smarty3') {
$template = new FriendicaSmarty();
$template->filename = $template_file;
-// $tt = microtime() - $ts;
-// $a->page['debug'] .= "$tt <br>\n";
+ $stamp2 = microtime(true);
+ $duration = (float)($stamp2-$stamp1);
+ $a->performance["rendering"] += (float)$duration;
+
return $template;
}
else {
$template_file = get_template_file($a, $s, $root);
-// $file_contents = file_get_contents($template_file);
-// $tt = microtime() - $ts;
-// $a->page['debug'] .= "$tt <br>\n";
-// return $file_contents;
+
+ $stamp2 = microtime(true);
+ $duration = (float)($stamp2-$stamp1);
+ $a->performance["rendering"] += (float)$duration;
+
return file_get_contents($template_file);
- }
+ }
}}
if(! function_exists("get_template_file")) {