构建和安装 PHP 扩展程序
该扩展骨架无需任何修改即可编译。第一个 phpize
命令是我们在第一步中创建的 PHP 构建的一部分。(它应该还在 PATH
中)。
$ phpize
$ ./configure
$ make
$ make install
这些命令将创建我们的共享扩展 test.so
,并将其复制到 PHP 安装的适当目录中。要加载它,我们需要在自定义 php.ini
中添加一行内容:
$ vi ~/php-bin/DEBUG/etc/php.ini
添加以下一行:
extension=test.so
检查扩展是否已加载并正常运行。php -m
命令可打印已加载扩展的列表:
$ php -m | grep test
test
我们还可以运行 test 扩展中定义的函数:
$ php -r 'test_test1();'
The extension test is loaded and working!
$ php -r 'echo test_test2("world\n");'
Hello world
现在,开始使用版本控制系统跟踪源代码更改就变得很有意义了。(我更喜欢 GIT)。
$ git init
$ git add config.m4 config.w32 test.c php_test.h tests
$ git commit -m "Initial Extension Skeleton"