- A+
需要准备的材料
WEB环境 apache2.4+php5.6(自己的版本)
cygwin软件(可以在windows上操作SH)下载地址
其中在安装这个软件时会用到 http://mirrors.163.com/cygwin/ 这个镜像地址(速度比较快)
关于163镜像服务器
163是个好公司,因为刚看到http://mirrors.163.com/.help/中的介绍,得知其前身就是cn99镜像。之前玩过Ubuntu的人,估计多数都知道cn99这个镜像,因为对于国内来说,apt的源的地址中,属其速度最快。而且,现又发现,163的镜像,除了提供cygwin,其还提供了其他很多资源的镜像,都可以在http://mirrors.163.com/中找到。包括很多常见的,比如mandriva,openSUSE,ubuntu等等。 |
php5.6或其他版本的源码 下载地址
需要修改到的配置文件三个:
1.php源码包里的ext文件夹下的 ext_skel_win32.php
2.php5ts.lib 原文件是在系统已经安装好的PHP路径下的 dev文件夹里边 在生成 dll文件前时 需要将其拷贝到 源码包路径下的 ext/对应的自己的扩展文件夹下
3.config.w32.h 原文件是在源码包下的 win32/build/config.win32.h.in
以下是具体的流程:
2019-08-07 最近一直在用windows上来制作扩展(垃圾,一直做不出来报错,最后不报错了,制作出 dll文件 安装上还是不能用)郁闷
现在开始 linux上的制作 开始:
准备条件 php源码 安装好的环境 一定想相对应(版本一致)
https://museum.php.net/php5/ 下载php源码包的必要网站
Creating directory helloyo
Creating basic files: config.m4 config.w32 .gitignore helloyo.c php_helloyo.h CREDITS EXPERIMENTAL tests/001.phpt helloyo.php [done].
To use your new extension, you will have to execute the following steps:
1. $ cd ..
2. $ vi ext/helloyo/config.m4
3. $ ./buildconf
4. $ ./configure --[with|enable]-helloyo
5. $ make
6. $ ./sapi/cli/php -f ext/helloyo/helloyo.php
7. $ vi ext/helloyo/helloyo.c
8. $ make
以上代码是ext_skel 给出的制作扩展的流程 挺详细的(后来了解到可以用 phpize直接编写)
流程如下:
准备工作
1.安装好了 php环境
2.php源码(可以从我上边的链接来下载)
我的路径 说明 /www/server/php/56/ (宝塔软件) 源码在 /home/tool/php-5.6.4 (用phpinfo查看的版本然后下载的相对应的源码)
生成基础配置文件 config.m4
cd /home/tool/php-5.6.4/ext
./ext_skel helloyo
vi helloyo/config.m4
修改配置
将原来的
dnl PHP_ARG_ENABLE(helloyo, whether to enable helloyo support,
dnl Make sure that the comment is aligned:
dnl [ --enable-helloyo Enable helloyo support])
修改为
PHP_ARG_ENABLE(helloyo, whether to enable helloyo support,
[ --enable-helloyo Enable helloyo support])
:wq #保存退出
编写C代码
进入helloyo文件,用ls查看目录
/home/tool/php-5.6.4/ext/helloyo # ls
config.m4 config.w32 CREDITS EXPERIMENTAL helloyo.c helloyo.php php_helloyo.h .svnignore tests
编辑php_helloyo.h,加入say_hello函数入口
vim php_helloyo.h
#ifdef ZTS
#define HELLOYO_G(v) TSRMG(helloyo_globals_id, zend_helloyo_globals *, v)
#else
#define HELLOYO_G(v) (helloyo_globals.v)
#endif
#endif /* PHP_HELLOYO_H */
PHP_FUNCTION(confirm_helloyo_compiled); #在底部加入这个
PHP_FUNCTION(say_hello); #在底部加上这个
编辑helloyo.c,需要修改两处内容
vim helloyo.c
/* {{{ helloyo_functions[]
*
* Every user visible function must have an entry in helloyo_functions[].
*/
const zend_function_entry helloyo_functions[] = {
PHP_FE(confirm_helloyo_compiled, NULL) /* For testing, remove later. */
PHP_FE(say_hello, NULL) /* say hello to someone. 这里是新加的 */
PHP_FE_END /* Must be the last line in helloyo_functions[] */
};
在底部在写入
PHP_FUNCTION(say_hello)
{
char *arg = NULL;
int arg_len,len;
char *strg;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
return;
}
len = spprintf(&strg,0,"Hello,%s!\n", arg);
RETURN_STRINGL(strg,len,0);
}
:wq #保存退出
编译安装
进入 helloyo目录下运行phpize命令,phpize可以用来为php扩展来构建环境
[root@localhost etc]# /www/server/php/56/bin/phpize
完成后会产生 configure 如图

然后运行 配置命令
./configure --with-php-config=/www/server/php/56/bin/php-config
make
make test
make install
Installing shared extensions: /www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/
结果如上所示就是成功了
接下来修改配置
#修改php.ini 可以通过 phpinfo(); 来查看 php.ini的存放位置
extension=helloyo.so
验证与运行
php -m

用 cli ent命令运行
php -r "echo say_hello('jack');"
hello,jack!
用cgi网页 在网页上看需要重启php 再查看phpinfo();

至此完成初步的扩展搭建-接下来开始制作 mogodb的小扩展吧
- 我的微信
- 这是我的微信扫一扫
-
- 我的微信公众号
- 我的微信公众号扫一扫
-
2019年7月8日 下午2:46 沙发
http://note.youdao.com/groupshare/?token=0A1F890000B041488D9B2C8BA99C2CA8&gid=16190054