找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3581|回复: 0

php扩展xdebug安装与系统分析

[复制链接]
发表于 2011-12-17 10:17:53 | 显示全部楼层 |阅读模式
一:安装
安装方法一:编译安装
  1. 1、下载PHP的XDebug扩展,网址:http://xdebug.org/
  2. # wget http://pecl.php.net/get/xdebug-2.1.2.tgz
  3. # tar -xzf xdebug-2.1.2.tgz
  4. # xdebug-2.1.2
  5. # cd xdebug-2.1.2
  6. # /usr/local/php/bin/phpize
  7. # ./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config
  8. # make && make install
复制代码

不需要自己拷贝xdebug.so了,下面可以省。
# cp modules/xdebug.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613
注:/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/不同的PHP版本路径不同,也不一定要放在该路径,可以在zend_extension_ts中自行指定xdebug.so所在位置。
================================================
安装方法二:自动安装
http://pecl.php.net/package/xdebug

# /usr/local/php/bin/pecl install xdebug
安装成功


===============================================
二:修改php配置模块
1.配置
修改php.ini,去除PHP加速模块,增加以下配置信息支持XDebug扩展

手动安装
  1. [Xdebug]
  2. zend_extension_ts="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so"
  3. xdebug.profiler_enable=on
  4. xdebug.trace_output_dir="/tmp/xdebug"
  5. xdebug.profiler_output_dir="/tmp/xdebug"
复制代码

自动安装
  1. [Xdebug]
  2. extension=xdebug.so
  3. xdebug.profiler_enable=on
  4. xdebug.trace_output_dir="/tmp/xdebug"
  5. xdebug.profiler_output_dir="tmp/xdebug"
复制代码
------------------------------
2.权限
  1. mkdir -p /tmp/xdebug
  2. chmod 755 /tmp/xdebug
  3. chown www:www /tmp/xdebug
复制代码
-----------------------------
3.重启
/usr/local/apache/bin/apachectl restart

说明:如果phpinfo()没有打印这个信息说明没有配置正确!
------------------------------
4.停用
说明:如果不分析系统一定要记得关闭xdebug.profiler不然会生成许多文件
xdebug.profiler_enable=off
====================================
三:分析系统
1.访问你的网站
将首页上各种链接点击几遍,XDebug在/tmp/xdebug目录生成文件

2.使用图形分析工具wincachedgrind分析生成的文件
下载地址:http://sourceforge.net/projects/wincachegrind/files/


3.下载图形化工具kcachegrind在windows下的可执行版
下载地址http://sourceforge.net/projects/precompiledbin/files

用kcachegrind来看会更形象,注意需要修改从linux中执行的文件的php文件路径,这样就可以了sourcecode.


查看代码执行顺序


更复杂的代码:
  1. <?php
  2.     define( 'BOOSTER', 5 );
  3.     define( 'CAPSULE', 2 );
  4.     define( 'MINUTE', 60 );
  5.     define( 'STAGE', 3 );
  6.     define( 'PRODUCTION', 1000 );
  7.    
  8.     class Part {
  9.         function Part() {
  10.             $this->build( MINUTE );
  11.         }
  12.         
  13.         function build( $delay = 0 ) {
  14.             if ( $delay <= 0 )
  15.                 return;
  16.                
  17.             while ( $delay-- > 0 ) {
  18.             }
  19.         }
  20.     }
  21.    
  22.     class Capsule extends Part {
  23.         function Capsule() {
  24.           parent::Part();
  25.             $this->build( CAPSULE * MINUTE );
  26.         }
  27.     }
  28.    
  29.     class Booster extends Part {
  30.         function Booster() {
  31.           parent::Part();
  32.             $this->build( BOOSTER * MINUTE );
  33.         }
  34.     }
  35.    
  36.     class Stage extends Part {
  37.         function Stage() {
  38.           parent::Part();
  39.           $this->build( STAGE * MINUTE );
  40.         }
  41.     }
  42.    
  43.     class SpaceShip {
  44.         var $booster;
  45.         var $capsule;
  46.         var $stages;
  47.         
  48.         function SpaceShip( $numberStages = 3 ) {
  49.             $this->booster = new Booster();
  50.             $this->capsule = new Capsule();
  51.             $this->stages = array();
  52.             
  53.             while ( $numberStages-- >= 0 ) {
  54.                 $stages[$numberStages] = new Stage();
  55.             }
  56.         }
  57.     }
  58.    
  59.     $toys = array();
  60.     $count = PRODUCTION;
  61.    
  62.     while ( $count-- >= 0  ) {
  63.       $toys[] = new SpaceShip( 2 );
  64.     }
  65. ?>
  66. <html>
  67. <head>
  68. <title>
  69. Toy Factory Output
  70. </title>
  71. </head>
  72. <body>
  73.   <h1>Toy Production</h1>
  74.   <p>Built <? echo PRODUCTION . ' toys' ?></p>
  75. </body>
  76. </html>
复制代码

分析日志


其他使用参考:xdebug基本使用 ===================================参考&quot

为 PHP 应用提速、提速、再提速!,第 2 部分: 分析 PHP 应用程序以查找、诊断和加速运行缓慢的代码
http://www.ibm.com/developerworks/cn/opensource/os-php-fastapps2/index.html

http://hi.baidu.com/%D4%E7%B9%C8%C9%E7%C7%F8/blog/item/d8fedafb7843c66b024f56cb.html

使用Xdebug跟踪代码执行
http://book.51cto.com/art/200906/126516.htmKCacheGrind windows 系統下的代替方案
  • WinCacheGrind
    可分析由xdebug產出的cachegrind.xxx檔,簡易版的kcachegrind。
  • windows port of kcachegrind
    由原linux的kcachegrind,重新編譯在windows上可執行版,功能與linux kcachegrind相同。
  • Webgrind
    網頁版的callgrind,搭配xdebug可做即時線上做php script profile。



===================================
另外还有一个扩展也很好:
http://pecl.php.net/package/xhprof
安装参考:
http://www.phpv5.com/blog/archives/66作者:21aspnet 发表于2011-12-2 18:47:19 原文链接
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-5-1 20:43 , Processed in 0.014744 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表