构思是include两个php程序,一个renderheader.php,一个renderfooter.php.分别在页面的开头和结尾include这两个文件,就可以无缝的整合profiling到现有的程序当中。
renderheader.php
renderfooter.php
renderbody.php
本系列的文章暂时告一段落,希望对爱好php的朋友有所帮助。
[~/c_xml_so]# mkdir logs3
[~/c_xml_so]# vi logs3/2010-04-22.log
[2010/04/22 02:55:23] renderbody.php 2663.10095787
http://blog.sina.com.cn/s/blog_4d8a2c970100etx2.html
renderheader.php
<?php
$time_start = getmicrotime();
$filename="logs3/".date("Y-m-d",mktime()).".log";
$scriptName=$_SERVER["SCRIPT_NAME"];
echo $scriptName;
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function logToFile($filename, $msg,$scriptName)
{
$fd = fopen($filename, "a") or die ("Can't open file ".$filename);
// append date/time to message
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " ." ".$scriptName." ".$msg;
// write string
fwrite($fd, $str . "\n");
// close file
fclose($fd);
}
?>
$time_start = getmicrotime();
$filename="logs3/".date("Y-m-d",mktime()).".log";
$scriptName=$_SERVER["SCRIPT_NAME"];
echo $scriptName;
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function logToFile($filename, $msg,$scriptName)
{
$fd = fopen($filename, "a") or die ("Can't open file ".$filename);
// append date/time to message
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " ." ".$scriptName." ".$msg;
// write string
fwrite($fd, $str . "\n");
// close file
fclose($fd);
}
?>
renderfooter.php
<?php
$time_end = getmicrotime();
$msg=($time_end - $time_start)*1000;
logToFile($filename,$msg,$scriptName);
printf ("page render time: %.2fms\n\n",($time_end - $time_start)*1000);
?>
$time_end = getmicrotime();
$msg=($time_end - $time_start)*1000;
logToFile($filename,$msg,$scriptName);
printf ("page render time: %.2fms\n\n",($time_end - $time_start)*1000);
?>
renderbody.php
<?php
include("renderheader.php");
for ($i=1;$i<=10000;$i++)
{
echo "hello wade"."</br>";
}
include("renderfooter.php");
?>
include("renderheader.php");
for ($i=1;$i<=10000;$i++)
{
echo "hello wade"."</br>";
}
include("renderfooter.php");
?>
本系列的文章暂时告一段落,希望对爱好php的朋友有所帮助。
[~/c_xml_so]# mkdir logs3
[~/c_xml_so]# vi logs3/2010-04-22.log
[2010/04/22 02:55:23] renderbody.php 2663.10095787
http://blog.sina.com.cn/s/blog_4d8a2c970100etx2.html
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/2978/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2010-4-22 14:56
评论列表