生成扩展骨架。cd ext
执行命令
php ext_skel.php --ext zhouso
输出信息
Copying config scripts... done
Copying sources... done
Copying tests... done
Success. The extension is now ready to be compiled. To do so, use the
following steps:
cd /www/server/php/81/src/ext/zhouso
phpize
./configure
make
Don't forget to run tests once the compilation is done:
make test
随便添加一个函数,更改 zhouso.stub.php
<?php
/** @generate-class-entries */
function test1(): void {}
function test2(string $str = ""): string {}
function generatedomain(string $str = ""): string {}
重新生成 zhouso_arginfo.h
php ../../build/gen_stub.php zhouso.stub.php
第一次会下载PHP-Parser
执行命令
phpize
检测安装平台的目标特征的生成一个makefile文件
执行命令
./configure
如果提示
configure: error: Cannot find php-config. Please use --with-php-config=PATH
执行命令
./configure --with-php-config=/www/server/php/81/bin/php-config
编译生成so
make
复制生成的so文件到/www/server/php/81/lib/php/extensions,并配置php.ini
配置文件后加入,重启php
extension = /www/server/php/81/lib/php/extensions/zhouso.so