当前位置: 移动技术网 > IT编程>开发语言>PHP > 详解Window7 下开发php扩展

详解Window7 下开发php扩展

2018年04月19日  | 移动技术网IT编程  | 我要评论

一、首先查看phpinfo() 信息

php version 5.4.34
zend extension build api220100525,ts,vc9
php extension build api20100525,ts,vc9
thread safety enable

线程安全,vc9编译,5.4.34版本

二、开发前准备工作

php 5.3-5.4 :visual c++ 9.0(visual studio 2008)
安装cygwin(下载地址:http://www.cygwin.com/),虚拟linux环境
php编译后的程序和编译前的源码(下载地址:http://windows.php.net/download/)
编译后的程序路径:php-5.4.45-win32-vc9-x86\
编译前的源码路径:php-5.4.45-src\
下载php sdk文件,http://windows.php.net/downloads/php-sdk/

1、解压php-sdk-binary-tools-20110915.zip里面的文件,将bison.exe所在的bin目录添加的系统path

将php-5.4.45-win32-vc9-x86\dev\php5ts.lib 复制到php-5.4.45-src\release_ts\php5ts.lib
新建php-5.4.45-src\main\config.win32.h,内容如下:
#define sizeof_long 4
#define php_compiler_id "vc9"
"vc9"对应vc9

2、找到php源码目录, php-5.4.45-src\ext\ext_skel_win32.php

/*
this script can be used on win systems
) make sure you have cygwin installed
) adjust the $cygwin_path to match your installation
) change the environment cariable pathext to include .php
) run ext_skel --extname=...
the first time you run this script you will be asked to
associate it with a program. chooses the cli version of php.
*/
$cygwin_path = 'd:\program files\cygwin\bin'; 

这里改成你的cygwin安装目录。

3、运行cmd,进入php源码目录, php-5.4.45-src\ext,运行命令php ext_skel_win32.php --extname=myphpexs


记得将php.exe 所在目录加入path,--extname=你的扩展名字,

若成功会再ext目录下生成myphpexs文件夹,内容如下


4、用vs2008 打开myphpexs.dsp, 解决方案配置改为release,执行生成命令

顺利的话将生成php_myphpexs.dll文件,我的将php_myphpexs.dll生成再了php源码根目录的release_ts文件夹中

5、将php_myphpexs.dll放到你php的扩展目录,再php.ini中加上extension=php_myphpexs.dll

6、新建php脚本文件test.php,内容如下

复制代码 代码如下:

echo confirm_myphpexs_compiled('test');

7、运行测试文件,出现如下内容说明,成功了

复制代码 代码如下:

congratulations! you have successfully modified ext/myphpext/config.m4. module 23 is now compiled into php.

8、confirm_myphpexs_compiled是建立扩展是自带的册数函数,在编辑你自己的扩展内容时,可以删除改函数

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网