Repository navigation
Expand file tree
/
Copy path5.3.txt
More file actions
20 lines (14 loc) · 2.24 KB
/
Copy path5.3.txt
File metadata and controls
20 lines (14 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
静态编译
5.2
5.4
#
<p>我们检查一下PHP语言中get_loaded_extensions()函数的输出,会发现有一些扩展并没有php.ini文件中调用,而它们确实也已经加载到PHP里去了,可以让我们在PHP语言中使用,如standard、Reflection、Core等。它们便是静态编译的,它们没有被编译成so或者dll文件供PHP动态调用,而是直接和PHP主程序编译到一起。</p>
<h3>在*nix上执行静态编译</h3>
<p>现在,先让我们执行一下PHP源码根目录下的./configure --help命令。会发现输出信息并没有包含我们的扩展,这是因为这个configure脚本生成的时候,我们的扩展还没有编写呢。(这个configure是PHP官方分发的。),所以首先我们需要使用buildconf命令生成新的configure脚本。</p>
<p>$ ./buildconf --force</p>
<div class="tip-common">If you're using a production release of PHP to do development against, you'll find that ./buildconf by itself doesn't actually work. In this case you'll need to issue: ./buildconf force to bypass some minor protection built into the ./configure command.</div>
<p>现在当我们再执行./configure --help的时候,便会发现walu扩展的信息已经出现了。现在我们只需要重新走一遍PHP的编译过程,便可以把我们的扩展以静态编译的方式加入到PHP主程序中了。哦,千万不要忘记使用--enable-walu参数开启我们的扩展。</p>
<p>当然,对于我们学习如何开发PHP扩展来讲,静态编译可不是一个好主意,因为如果采用静态编译的方式,只要我们的扩展坐了改动,便需要重新编译整个PHP才行,这个过程太痛苦了。还是用前一节的方式吧。但是这种方式有利于提高性能,所以如果我们是在部署生产环境,则可以考虑!</p>
<h3>Building Statically Under Windows</h3>
<p>Regenerating the configure.js script for Windows follows the same pattern as regenerating the ./configure script for *nix. Navigate to the root of the PHP source tree and reissue buildconf.bat as you did in Chapter 4.</p>
<p>The PHP build system will scan for config.w32 files, including the one you just made for ext/sample, and generate a new configure.js script with which to build a static php binary.</p>