<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>潘锦的空间 &#187; PHP源码结构</title>
	<atom:link href="https://www.phppan.com/tag/php%e6%ba%90%e7%a0%81%e7%bb%93%e6%9e%84/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.phppan.com</link>
	<description>SaaS SaaS架构 团队管理 技术管理 技术架构 PHP 内核 扩展 项目管理</description>
	<lastBuildDate>Sat, 04 Apr 2026 01:19:58 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>TIPI0102&#8211;PHP源码结构、阅读代码方法</title>
		<link>https://www.phppan.com/2011/01/tipi0102-code-structure/</link>
		<comments>https://www.phppan.com/2011/01/tipi0102-code-structure/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 03:40:03 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP源码结构]]></category>
		<category><![CDATA[TIPI]]></category>
		<category><![CDATA[深入理解PHP内核]]></category>
		<category><![CDATA[阅读代码方法]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=1221</guid>
		<description><![CDATA[第二节 PHP源码结构、阅读代码方法 PHP源码目录结构: 俗话讲：大巧不工。PHP的源码在结构上非常清晰甚至 [&#8230;]]]></description>
				<content:encoded><![CDATA[<h1>第二节 PHP源码结构、阅读代码方法</h1>
<h2>PHP源码目录结构:</h2>
<hr />
<p style="text-indent: 2em;">俗话讲：大巧不工。PHP的源码在结构上非常清晰甚至简单。下面，先简单介绍一下PHP源码的目录结构。</p>
<ul>
<li><strong>build</strong>: 源码编译相关文件，包括buildconft等sh文件，还有一些awk的脚本。</li>
<li><strong>ext</strong> 官方扩展目录，包括了绝大多数PHP的函数的定义和实现，如array系列，pdo系列，spl系列等函数的实现，都在此处相对的子目录中。</li>
<li><strong>main</strong> PHP宏定义与实现，在需要扩展PHP时，经常要使用的PHP_*系列宏就在这里定义。</li>
<li><strong>Zend</strong> 包含Zend引擎文件，Zend API宏的定义和实现。</li>
<li><strong>pear</strong> “PHP 扩展与应用仓库”, 包含PEAR的核心文件。</li>
<li><strong>sapi</strong> 包含了各种服务器抽象层的代码，以目录区分。</li>
<li><strong>TSRM</strong> “线程安全资源管理器” (TSRM) 目录。</li>
<li><strong>tests</strong> 测试脚本目录。</li>
<li><strong>win32</strong> Windows 下编译PHP相关的脚本。</li>
</ul>
<h2>PHP源码阅读方法:</h2>
<hr />
<h4>使用VIM + Ctags查看并追踪源码：</h4>
<p style="text-indent: 2em;">VIM是一个非常给力的编辑器，在纯命令终端下，它几乎是无可替代的（Emacs？）。<br />
ctags可以将源代码中的各种函数、宏等信息做上标记。这样，使用VIM就可以很方便的查看源码。<br />
简洁使用说明：</p>
<pre style="background-color: #333333; color: #ffffff; font: normal normal normal 13px/normal 'Bitstream Vera Sans Mono', monospace; overflow-x: auto; overflow-y: auto; font-family: monospace; padding: 10px;"><span style="color: #bd48b3;">#在PHP源码目录(假定为/server/php-src)执行:</span>
$ <span style="color: #e2392d;">cd</span> <span style="color: #e0882f;">/</span>server<span style="color: #e0882f;">/</span>php-src
$ ctags <span>-R</span>

<span style="color: #bd48b3;">#在~/.vimrc中添加:</span>
<span style="color: #ff8400;">set</span> tags+=<span style="color: #e0882f;">/</span>server<span style="color: #e0882f;">/</span>php-src<span style="color: #e0882f;">/</span>tags</pre>
<p style="text-indent: 2em;">再用vim打开各种php源码文件时，将光标移到想查看的函数、宏、变量上面， 使用 <strong>Ctrl+p</strong> 就可以自动跳转至定义，<strong>Ctrl+o</strong> 可以返回上一次查看位置。</p>
<h4>使用Visual Studio + editplus查看并追踪源码：</h4>
<p style="text-indent: 2em;">看源码还是用IDE舒服一些，windows下我们还是用Visual Studio 2010看吧。 在win32目录下已经存在了可以直接打开的工程文件，如果由于版本原因无法打开，可以在此源码目录上新建一个基于现有文件的Win32 Console Application工程。<br />
<strong>常用快捷键</strong>：</p>
<pre style="background-color: #333333; color: #ffffff; font: normal normal normal 13px/normal 'Bitstream Vera Sans Mono', monospace; overflow-x: auto; overflow-y: auto; font-family: monospace; padding: 10px;">F12 转到定义
CTRL <span style="color: #e0882f;">+</span> F12转到声明

F3<span style="color: #e0882f;">:</span> 查找下一个
Shift<span style="color: #e0882f;">+</span>F3<span style="color: #e0882f;">:</span> 查找上一个

Ctrl<span style="color: #e0882f;">+</span>G<span style="color: #e0882f;">:</span> 转到指定行

CTRL <span style="color: #e0882f;">+</span> <span style="color: #e0882f;">-</span>向后定位
CTRL <span style="color: #e0882f;">+</span> SHIFT <span style="color: #e0882f;">+</span> <span style="color: #e0882f;">-</span>向前定位</pre>
<p style="text-indent: 2em;">对于一些搜索类的操作，可以考虑使用editplus或其它文本编辑工具进行，这样的搜索速度相对来说会快一些。<br />
如果使用editplus进行搜索，一般是选择 【搜索】 中的 【在文件中查找&#8230;】</p>
<p style="text-indent: 2em;">作者：TIPI Team</p>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2011/01/tipi0102-code-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
