Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 12107

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>APD 高级 PHP 调试器</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="函数参考"
HREF="funcref.html"><LINK
REL="PREVIOUS"
TITLE="apc_store"
HREF="function.apc-store.html"><LINK
REL="NEXT"
TITLE="apd_breakpoint"
HREF="function.apd-breakpoint.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="reference"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.apc-store.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.apd-breakpoint.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="reference"
><A
NAME="ref.apd"
></A
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
>IV. APD 高级 PHP 调试器</H1
><DIV
CLASS="PARTINTRO"
><A
NAME="AEN9666"
></A
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.intro"
>简介</A
></H1
><P
>&#13;    APD 是 Advanced PHP Debugger,即高级 PHP 调试器。是用来给
    PHP 代码提供规划与纠错的能力,以及提供了显示整个堆栈追踪的能力。APD
    支持交互式纠错,但默认是将数据写入跟踪文件。它还提供了基于事件的日志,因此不同级别的信息(包括函数调用,参数传递,计时等)可以对个别的脚本打开或关闭。
    <DIV
CLASS="caution"
><P
></P
><TABLE
CLASS="caution"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>小心</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;      APD 是一个 Zend 扩展库,修改了 PHP 内部处理函数调用的方式,因此有可能与其它
      Zend 扩展库(例如 Zend Optimizer)不兼容。
     </P
></TD
></TR
></TABLE
></DIV
>
   </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.installation"
>安装</A
></H1
><P
>&#13;  APD 目前作为一个 PECL 扩展,可以从
  <A
HREF="http://pecl.php.net/package/apd"
TARGET="_top"
>http://pecl.php.net/package/apd</A
>
  得到。确保安装了 CGI 版的 PHP 并且在当前目录下可以运行,以及可以运行 phpize 脚本。
 </P
><P
>&#13;  运行以下命令以下载,编译并安装最新稳定版的 APD:
 <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>pear install apd</PRE
></TD
></TR
></TABLE
>
 </P
><P
>&#13;  这将自动把 APD Zend 扩展安装到 PHP 扩展库目录中。不是一定要放到那里,可以将此模块存放到任何
  PHP 可以读取的目录中,只要正确设定了相应的 zend_extension 参数即可。
 </P
><P
>&#13;  Windows 用户可以从 <A
HREF="http://snaps.php.net/win32/PECL_STABLE/"
TARGET="_top"
>http://snaps.php.net/win32/PECL_STABLE/</A
>
  下载扩展库的 DLL 文件 <TT
CLASS="filename"
>php_apd.dll</TT
>。
 </P
><P
>&#13;  在 INI 文件中,加入下面几行:
 </P
><P
>&#13;  <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php.ini"
>zend_extension = /absolute/path/to/apd.so
apd.dumpdir = /absolute/path/to/trace/directory
apd.statement_tracing = 0</PRE
></TD
></TR
></TABLE
>
 </P
><P
>&#13;  根据 PHP 版本,zend_extension 指令可以是以下之一:
 </P
><P
>&#13;  <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="script"
>zend_extension              (non ZTS, non debug build)
zend_extension_ts           (    ZTS, non debug build)
zend_extension_debug        (non ZTS,     debug build)
zend_extension_debug_ts     (    ZTS,     debug build)</PRE
></TD
></TR
></TABLE
>
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.installwin32"
>在 Win32 下编译</A
></H1
><P
>&#13;  要在 Windows 下编译 APD,需要一个在 http://php.net/ 中说明的可用 PHP
  编译环境――基本上,需要有 Microsoft Visual C++,win32build.zip,bison/flex,以及相关知识。另外确保
  adp.dsp 具有 DOS 行结束符,如果是 Unix 的行结束符,Microsoft Visual C++ 会觉得有问题。
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.configuration"
>运行时配置</A
></H1
><P
>这些函数的行为受 <TT
CLASS="filename"
>php.ini</TT
> 的影响。</P
><P
>&#13;  <DIV
CLASS="table"
><A
NAME="AEN9696"
></A
><P
><B
>表 1. APD 配置选项</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><COL><THEAD
><TR
><TH
>名称</TH
><TH
>默认值</TH
><TH
>可修改范围</TH
><TH
>更新记录</TH
></TR
></THEAD
><TBODY
><TR
><TD
>apd.dumpdir</TD
><TD
>NULL</TD
><TD
>PHP_INI_ALL</TD
><TD
>&nbsp;</TD
></TR
><TR
><TD
>apd.statement_tracing</TD
><TD
>"0"</TD
><TD
>PHP_INI_ALL</TD
><TD
>&nbsp;</TD
></TR
></TBODY
></TABLE
></DIV
>
  有关 PHP_INI_* 常量进一步的细节与定义参见<A
HREF="ini.html"
>附录 H</A
>。
 </P
><P
>以下是配置选项的简要解释。</P
><P
>&#13;  <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><A
NAME="ini.apd.dumpdir"
></A
><CODE
CLASS="parameter"
>apd.dumpdir</CODE
>
     <A
HREF="language.types.string.html"
><B
CLASS="type"
>string</B
></A
></DT
><DD
><P
>&#13;      设定 APD 写入调试输出文件的目录。可以指定绝对路径或相对路径。
     </P
><P
>&#13;      可以在 <A
HREF="function.apd-set-pprof-trace.html"
><B
CLASS="function"
>apd_set_pprof_trace()</B
></A
> 中以参数指定一个不同目录。
     </P
></DD
><DT
><A
NAME="ini.apd.statement-tracing"
></A
><CODE
CLASS="parameter"
>apd.statement_tracing</CODE
>
     <A
HREF="language.types.boolean.html"
><B
CLASS="type"
>boolean</B
></A
></DT
><DD
><P
>&#13;      指定是否进行每行的跟踪。将此项打开(设为 1)将影响到程序的性能。
     </P
></DD
></DL
></DIV
>
 </P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.resources"
>资源类型</A
></H1
><P
>本扩展模块未定义任何资源类型。</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.constants"
>预定义常量</A
></H1
><P
>本扩展模块未定义任何常量。</P
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.examples"
>怎样在脚本中使用 PHP-APD</A
></H1
><DIV
CLASS="procedure"
><OL
TYPE="1"
><LI
CLASS="step"
><P
>&#13;      在 PHP 脚本的第一行调用 apd_set_pprof_trace() 函数来启动跟踪:
     </P
><P
>&#13;      <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
apd_set_pprof_trace();</font>
</code></TD
></TR
></TABLE
>
     </P
><P
>&#13;      可以在脚本中任何一行插入这一行,但是如果不是从脚本开头开始跟踪的话,则丢失了部分数据,有可能造成性能上的瓶颈。
     </P
></LI
><LI
CLASS="step"
><P
>&#13;      然后运行脚本。输出将被写入到 <TT
CLASS="filename"
>apd.dumpdir/pprof_pid.ext</TT
>。
      <DIV
CLASS="tip"
><BLOCKQUOTE
CLASS="tip"
><P
><B
>提示: </B
>
        如果运行的是 CGI 版的 PHP,需要加入 '-e'
        标记启用扩展信息以使 APD 正常工作。例如:
        <KBD
CLASS="userinput"
>php -e -f script.php</KBD
>
       </P
></BLOCKQUOTE
></DIV
>
     </P
></LI
><LI
CLASS="step"
><P
>&#13;      要显示格式化的调试数据,运行 <B
CLASS="command"
>pprofp</B
>
      命令并加上自己选择的排序和显示选项。格式化的输出类似于:
      <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>bash-2.05b$ pprofp -R /tmp/pprof.22141.0

Trace for /home/dan/testapd.php
Total Elapsed Time = 0.00
Total System Time  = 0.00
Total User Time    = 0.00


Real         User        System             secs/    cumm
%Time (excl/cumm)  (excl/cumm)  (excl/cumm) Calls    call    s/call  Memory Usage Name
--------------------------------------------------------------------------------------
100.0 0.00 0.00  0.00 0.00  0.00 0.00     1  0.0000   0.0009            0 main
56.9 0.00 0.00  0.00 0.00  0.00 0.00     1  0.0005   0.0005            0 apd_set_pprof_trace
28.0 0.00 0.00  0.00 0.00  0.00 0.00    10  0.0000   0.0000            0 preg_replace
14.3 0.00 0.00  0.00 0.00  0.00 0.00    10  0.0000   0.0000            0 str_replace</PRE
></TD
></TR
></TABLE
>
     </P
><P
>&#13;      上例中用的 -R 选项将调试数据表格以脚本执行每个函数所花的时间来排序。"cumm call"
      一列显示了每个函数被调用的次数,"s/call" 一列显示了每个函数每次调用平均所花的秒数。
     </P
></LI
><LI
CLASS="step"
><P
>&#13;      要生成可以导入到 KCacheGrind 调试分析系统中的调用树文件,运行
      <B
CLASS="command"
>pprof2calltree</B
> 命令。
     </P
></LI
></OL
></DIV
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="apd.contact"
>联系信息</A
></H1
><P
>&#13;    如果有注解,错误修正,提高或者想帮助开发此扩展,请发送邮件到
    <A
HREF="mailto:apd@mail.communityconnect.com"
TARGET="_top"
>apd@mail.communityconnect.com</A
>。欢迎任何帮助。
   </P
></DIV
></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>目录</B
></DT
><DT
><A
HREF="function.apd-breakpoint.html"
>apd_breakpoint</A
>&nbsp;--&nbsp;Stops the interpreter and waits on a CR from the socket</DT
><DT
><A
HREF="function.apd-callstack.html"
>apd_callstack</A
>&nbsp;--&nbsp;Returns the current call stack as an array</DT
><DT
><A
HREF="function.apd-clunk.html"
>apd_clunk</A
>&nbsp;--&nbsp;Throw a warning and a callstack</DT
><DT
><A
HREF="function.apd-continue.html"
>apd_continue</A
>&nbsp;--&nbsp;Restarts the interpreter</DT
><DT
><A
HREF="function.apd-croak.html"
>apd_croak</A
>&nbsp;--&nbsp;Throw an error, a callstack and then exit</DT
><DT
><A
HREF="function.apd-dump-function-table.html"
>apd_dump_function_table</A
>&nbsp;--&nbsp;Outputs the current function table</DT
><DT
><A
HREF="function.apd-dump-persistent-resources.html"
>apd_dump_persistent_resources</A
>&nbsp;--&nbsp;Return all persistent resources as an array</DT
><DT
><A
HREF="function.apd-dump-regular-resources.html"
>apd_dump_regular_resources</A
>&nbsp;--&nbsp;Return all current regular resources as an array</DT
><DT
><A
HREF="function.apd-echo.html"
>apd_echo</A
>&nbsp;--&nbsp;Echo to the debugging socket</DT
><DT
><A
HREF="function.apd-get-active-symbols.html"
>apd_get_active_symbols</A
>&nbsp;--&nbsp;Get an array of the current variables names in the local scope</DT
><DT
><A
HREF="function.apd-set-pprof-trace.html"
>apd_set_pprof_trace</A
>&nbsp;--&nbsp;Starts the session debugging</DT
><DT
><A
HREF="function.apd-set-session-trace.html"
>apd_set_session_trace</A
>&nbsp;--&nbsp;Starts the session debugging</DT
><DT
><A
HREF="function.apd-set-session.html"
>apd_set_session</A
>&nbsp;--&nbsp;Changes or sets the current debugging level</DT
><DT
><A
HREF="function.apd-set-socket-session-trace.html"
>apd_set_socket_session_trace</A
>&nbsp;--&nbsp;Starts the remote session debugging</DT
><DT
><A
HREF="function.override-function.html"
>override_function</A
>&nbsp;--&nbsp;Overrides built-in functions</DT
><DT
><A
HREF="function.rename-function.html"
>rename_function</A
>&nbsp;--&nbsp;Renames orig_name to new_name in the global function table</DT
></DL
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.apc-store.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.apd-breakpoint.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>apc_store</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="funcref.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>apd_breakpoint</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>