skey / skey.github.com

个人博客
1 stars 0 forks source link

使用C语言编写PHP扩展 #5

Open skey opened 11 years ago

skey commented 11 years ago

如题

skey commented 11 years ago
1 安装php开发环境包
sudo apt-get install php5-dev  
2 下载php源码
sudo apt-get source php5  
3 生成php扩展
cd /php5-5.4.6/ext 
./ext_skel --extname=skey       (扩展名称) 

Creating directory skey 
Creating basic files: config.m4 config.w32 .svnignore skey.c php_skey.h CREDITS EXPERIMENTAL tests/001.phpt skey.php     [done].

To use your new extension, you will have to execute the following steps:

1.  $ cd ..
2.  $ vi ext/skey/config.m4
3.  $ ./buildconf
4.  $ ./configure --[with|enable]-skey
5.  $ make
6.  $ ./php -f ext/skey/skey.php
7.  $ vi ext/skey/skey.c
8.  $ make
4 修改编译文件
dnl  PHP_ARG_WITH(skey, for skey support,
dnl  Make sure that the comment is aligned:
dnl  [  --with-skey             Include skey support])

修改为

PHP_ARG_WITH(skey, for skey support, 
Make sure that the comment is aligned:
[  --with-skey             Include skey support])
5 安装扩展
  phpize
  ./configure
  make
  make install
6 加载扩展
  php.ini 增加 extension=skey.so     
7 测试代码
 <?php
   echo confirm_skey_compiled("skey"); 
 ?>

 加载成功后会输出

 Congratulations! You have successfully modified ext/skey/config.m4. Module skey is now compiled into PHP