专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » phpxdebug:php xdebug 使用 »正文

phpxdebug:php xdebug 使用

来源: 发布时间:星期一, 2009年1月12日 浏览:13次 评论:0
  听说xdebug 大名,等见到他时候已经是 xdebug 2.0.0rc3 发行版了没有用过Xdebug 1.3.1感觉就是 profile 变化比较大正好需要就是php profile 功能.我照着他 下载他 doc.tar.gz 解压发现里面就是几个txt文件后来才发现写还都是1.3.上官方网站WebSite在线文档才能看到提供下载文档都以落后了主页上面文档还是很全又学会

  经常上他主页看看不管有没有更新

  安装很顺利就是,完毕的后不知道如何开启功能个看到明显变化就是var_dump

  输出变地漂亮些再也没有发现什么debug 功能目前不需要感觉有时间debug 不如多几个var_dump

  和注释掉些代码多测试几便打断点和启动debug 时间太长了

  后来xdebug.org/docs-profiling2.php

  找到profile 文档

  测试了php 5 中 file_get_contents php4 中使用php写 et_get_file_contents 功能

  测试结果在大概性能1:4左右

  等有时间了写分详细点,

  php.in加入xdebug设置

  zend_extension="/opt/lib/xdebug.so"

  xdebug.profiler_enable=On

  xdebug.show_exception_trace=1

  xdebug.auto_trace=On

  xdebug.auto_profile=On

  xdebug.profiler_output_dir=/profile

  xdebug.profiler_output_name=script

  xdebug.profiler_append=1

  zend_extension="/opt/lib/xdebug.so"

  加载xdebug,使用是zend_extension,而非extension

  xdebug.auto_profile=On

  开启自动profile功能

  xdebug.profiler_output_dir

  设置xdebug profiler数据存放目录

  xdebug.profiler_output_name=script

  设置xdebug profiler输出数据文件以php script名字

  如mnt_d_phplib_phpsys2_phpinfo_php_cachegrind.out

  否则cachegrind.out.1447918559

  xdebug.profiler_append=1

  是否追加到文件里面统计结果以累计运行次数计算

  还是每次运行计算覆盖上次profile结果.

  profiler输出数据文件比较大如果都append

  压力测试时候会产生很多数据上面个小例子产生540多k数据

  www:/opt/APC-3.0.14 # php -v

  PHP 5.2.2 (cli) (built: May 5 2007 18:43:05)

  Copyright (c) 1997-2007 The PHP Group

  Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

  with Xdebug v2.0.0RC3, Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, by Derick Rethans

  建立/profile目录归属于daemon组(apache)

  xdebugprofile数据存储目录

  www:/profile # ls -alh

  total 2.1M

  drwxr-xr-x 2 daemon root  4.0K May 28 23:10 .

  drwxr-xr-x 27 root  root  4.0K May 28 23:12 ..

  -rw-r--r-- 1 daemon daemon  81 May 11 16:07 cachegrind.out.1447918559

  -rw-r--r-- 1 daemon daemon  83 May 11 16:08 cachegrind.out.1684987209

  -rw-r--r-- 1 daemon daemon 251 May 11 16:04 cachegrind.out.2087252671

  -rw-r--r-- 1 daemon daemon 125 May 11 16:08 cachegrind.out.2223812003

  -rw-r--r-- 1 daemon daemon 229 May 11 17:00 cachegrind.out.2255568671

  -rw-r--r-- 1 daemon daemon 168 May 11 16:04 cachegrind.out.3504195729

  -rw-r--r-- 1 daemon daemon 590K May 11 17:05 cachegrind.out.3859082558

  -rw-r--r-- 1 daemon daemon  79 May 11 16:09 cachegrind.out.3862590652

  -rw-r--r-- 1 daemon daemon 380 May 11 16:31 cachegrind.out.3965311212

  -rw-r--r-- 1 daemon daemon 422 May 11 15:39 cachegrind.out.45974958

  -rw-r--r-- 1 daemon daemon 16K May 11 16:11 cachegrind.out.924881639

  -rw-r--r-- 1 daemon daemon 1.2M May 28 23:31 mnt_d_phplib_phpsys2_phpinfo_php_cachegrind.out

  -rw-r--r-- 1 root  root  4.1K May 24 22:06 ommand line code_cachegrind.out

  -rw-r--r-- 1 daemon daemon 273K May 24 21:05 opt_phplib_apc_php_cachegrind.out

  -rw-r--r-- 1 daemon daemon 607 May 24 20:51 opt_phplib_index_php_cachegrind.out

  -rw-r--r-- 1 daemon daemon  12 May 11 16:47 www

  测试文件

<?
  
$fileName="/proc/uptime";
$times=1000;
for($i=0;$i<$times;$i){
$contentsa=file_get_contents($fileName);
$contentse= ett_get_file_contents($fileName);
}
function ett_get_file_contents($file){
  $handle=fopen($file,"r");
  (!$handle){  
   "";  
  }
  $contents="";
  while($handle&&!feof($handle))
  {
    $line=fread($handle,4012);
    $contents.=$line;
  }
  
  fclose($handle);
   $contents;
}
?>




  测试ett_get_file_contents功能和file_get_contents功能

  两个作用都是读取文件全部内容file_get_contents是php5里面新增native

  ett_get_file_contents是使用php脚本写.

  测试结果运行时间快慢

  ett_get_file_contents占用大约62.3%时间file_get_contents大约占用9.3%时间.

  以下是

  使用KCachegrind查看结果/profile/mnt_d_phplib_phpsys2_phpinfo_php_cachegrind.out





0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: