我正在优化我的网站,我已经让MySQL慢查询登录了几天,但在经历了超过260M的查询后,它只记录了6个慢查询,这些都是我在phpMyAdmin上执行的特殊查询。我想知道是否有什么东西可以记录缓慢的PHP页面执行时间,以便我可以找到某些占用资源的页面,而不是特定的查询。
发布于 2009-06-04 07:25:35
首先是xdebug,它有一个分析器,但我不会在生产机器上使用它,因为它注入代码并使速度变得缓慢。不过,这对于测试环境来说非常好。
如果您想在生产环境中测量速度,我只需要手动测量即可。microtime()就是用来处理这些事情的函数。假设你有一个header.php和一个footer.php,所有的php脚本都会调用它们:
# In your header.php (or tpl)
$GLOBALS['_execution_start'] = microtime(true);
# In your footer.php (or tpl)
file_put_contents(
'/tmp/my_profiling_results.txt',
microtime(true) - $GLOBALS['_execution_start'] . ':' . print_r($_SERVER, true) . "\n",
FILE_APPEND
);发布于 2010-07-14 14:22:23
http://blog.xrado.si/post/php-slow-log刚刚写了一篇关于auto_prepend_file和auto_append_file的文章
发布于 2009-06-04 07:20:41
您可以将脚本包装在一个简单的计时器中,如下所示:
/*in your header or at the top of the page*/
$time_start = microtime(true);
/* your script goes here */
/*in your footer, or at the bottom of the page*/
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "It took $time seconds\n";请注意,这将增加两个函数执行和少量的数学开销。
https://stackoverflow.com/questions/949034
复制相似问题