第一个php扩展hello world

1.进入php源码ext目录下

./ext_skel --extname=helloworld

如果一切顺利,你将看到



2.

cd helloworld
修改config.m4文件,把dnl去掉如下


3.执行phpize (php目录/bin/phpize)

如果顺利你将看到这么多文件


4.修改php_helloworld.h 

PHP_FUNCTION(confirm_helloworld_compiled);修改为PHP_FUNCTION(helloworld);//php方法名

5.修改helloworld.c

PHP_FUNCTION(confirm_helloworld_compiled){
    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, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "helloworld", arg);
    RETURN_STRINGL(strg, len, 0); 
}
改为:
PHP_FUNCTION(helloworld)
{
    char *arg = "hello world!!!";
    int  len;
    char *strg;

    len = spprintf(&strg, 0, "%s\n", arg);
    RETURN_STRINGL(strg, len, 0);   
}

PHP_FE(confirm_helloworld_compiled, NULL)改为 PHP_FE(helloworld, NULL)

6.执行./configure 

7.执行make

8.执行make install

如果顺利你将看到

PS:由于某些原因必须打马赛克。。

9.修改php.ini

增加extension=helloworld.so

10.重启php

php -m 你将看到helloworld

11.test



PS:附上php5.2.17源码下载地址

http://pan.baidu.com/s/1dDHw49r

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值