返回首页 PHP 扩展开发及内核应用相关内容

静态编译

我们检查一下PHP语言中get_loaded_extensions()函数的输出,会发现有一些扩展并没有php.ini文件中调用,而它们确实也已经加载到PHP里去了,可以让我们在PHP语言中使用,如standard、Reflection、Core等。它们便是静态编译的,它们没有被编译成so或者dll文件供PHP动态调用,而是直接和PHP主程序编译到一起。

在*nix上执行静态编译

现在,先让我们执行一下PHP源码根目录下的./configure --help命令。会发现输出信息并没有包含我们的扩展,这是因为这个configure脚本生成的时候,我们的扩展还没有编写呢。(这个configure是PHP官方分发的。),所以首先我们需要使用buildconf命令生成新的configure脚本。

$ ./buildconf --force 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.

现在当我们再执行./configure --help的时候,便会发现walu扩展的信息已经出现了。现在我们只需要重新走一遍PHP的编译过程,便可以把我们的扩展以静态编译的方式加入到PHP主程序中了。哦,千万不要忘记使用--enable-walu参数开启我们的扩展。

当然,对于我们学习如何开发PHP扩展来讲,静态编译可不是一个好主意,因为如果采用静态编译的方式,只要我们的扩展做了改动,便需要重新编译整个PHP才行,这个过程太痛苦了。还是用前一节的方式吧。但是这种方式有利于提高性能,所以如果我们是在部署生产环境,则可以考虑!

Building Statically Under Windows

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.

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.

上一篇: 编译我们的扩展 下一篇: 编写函数