Advice for a Hack?
Posted: Thu Aug 19, 2010 2:17 pm
Code removed 
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$start = microtime(true) * 1000;
Code: Select all
echo $start - microtime(true) * 1000;
Code: Select all
<?php
class Profiler
{
private $start;
private $log;
public function __construct()
{
$this->start = $this->get_time(false);
$this->log = array();
}
public function save($comment = "")
{
$backtrace = debug_backtrace();
$this->log[] = array
(
"file" => $backtrace[0]["file"],
"line" => $backtrace[0]["line"],
"comment" => $comment,
"time" => $this->get_time()
);
}
public function display()
{
if (count($this->log))
{
echo "<table id=\"profiler\">";
echo "<tr id=\"profiler_head\">";
foreach ($this->log[0] as $key => $value)
{
echo "<td>";
echo $key;
echo "</td>";
}
echo "</tr>";
foreach ($this->log as $key => $value)
{
echo "<tr>";
foreach ($this->log[$key] as $subkey => $subvalue)
{
echo "<td>";
echo $subvalue;
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
}
}
private function get_time($normalize = true)
{
$time = microtime(true) * 1000;
if ($normalize)
{
$time = $time - $this->start;
}
$time = substr($time, 0, strpos($time, ".") + 4);
return $time;
}
}
?>
Code: Select all
$profile = new Profiler();
$profile->save('start');
//do some stuff
$profile->save('done some stuff');
//do some other stuff
$profile->save('done');
$profile->display();
Code: Select all
$start = microtime(true);Code: Select all
$ps = $_SERVER["QUERY_STRING"];
if (!$ps) $ps = 'index';
$location = 'debug/'.$ps.'.txt';
$file = fopen($location, 'w');
fwrite($file, $ps.': '.(microtime(true) - $start));
fclose($file);Code: Select all
function thin($buffer) {
global $debug;
if (!$debug) {
$buffer = str_replace(array("\r", "\n", "\t"), '', $buffer);
$buffer = str_replace('> <', '><', $buffer);
global $d;
global $mobile;
if ($d == 'js' || $mobile) $buffer = preg_replace('#</?script[^>]*>.*?</script>#', '', $buffer);
if ($mobile) {
$buffer = str_replace('<i>', '', $buffer);
$buffer = str_replace('</i>', '', $buffer);
$i = 1;
while (preg_match('#<a href#', $buffer)) {
$buffer = preg_replace('#<a href#', '<a accesskey="' . $i . '" href', $buffer, 1);
$i++;
}
} else {
$buffer = str_replace('/>', '>', $buffer);
$buffer = ob_gzhandler($buffer, 9);
}
} else {
$buffer = str_replace("\n\n\n", "\n\n", $buffer);
}
return $buffer;
}
ob_start('thin');