目标:便携php扩展 要求实现 输出hello word

首先用的是php7.0.3   centos7.1或者centos6.+

1.1 RPM安装PHP
  • rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  • yum install php70w
  • php -v 看一下 7.0.3
  • php -m 看一下 php70w-devel, php70w-opcache模块安装没有,没有的话安装一下
  • PS:如果你的centos 是选择的低版本 这个(https://mirror.webtatic.com/yum/el7/webtatic-release.rpm)连接的中el7也得修改。
1.2 下载php源码包  注意版本
  • http://hk1.php.net/distributions/php-7.0.3.tar.gz (wget命令)
  • 把源码放在/usr/local/src/下解压

2.第一个扩展

2.1 输入:

[root@bogon ext]# cd /usr/local/src/php-7.0.3/ext

[root@bogon ext]# ./ext_skel --extname-hello

此时会生成:

cd hello/

ls  会看到几个文件

config.m4  config.w32  CREDITS  EXPERIMENTAL  hello.c  hello.php  php_hello.h  tests

2.2修改配置

[root@bogon ext]# vim hello/config.m4

  • dnl PHPARGWITH(hello, for hello support,
  • dnl Make sure that the comment is aligned:
  • dnl [ --with-hello Include hello support])
  • 更改为:
  • PHPARGWITH(hello, for hello support,
  • dnl Make sure that the comment is aligned:
  • [ --with-hello Include hello support])

2.3 代码实现

/*新增方法  该方法 必须放在  const zend_function_entry
* hello_functions[] 上面
*/
PHP_FUNCTION(hello)
{
zend_string *strg;
strg = strpprintf(0, "hello word");
RETURN_STR(strg);
} const zend_function_entry hello_functions[] = {
PHP_FE(hello, NULL) /* For testing, remove later. */
PHP_FE(confirm_hello_compiled, NULL)//这个可以删除了。
/* For testing, remove later. */
PHP_FE_END /* Must be the last line in hello_functions[] */
}

执行命令  phpize ( linux 下 用phpize 给php 动态添加扩展。)

如果phpize  执行失败   可能是缺少 gcc  (yum  install  gcc)

phpize  成功之后会生成一些文件

此时进行编译 ./configure

make  此时会有一个 modus 的文件夹  文件夹中会有2个文件

hello.la  hello.so

make install 或者 直接运行命令(cp modules/hello.so  /usr/lib64/php/modules)

同时 改更php.ini 加上

[hello]

extenstion=hello.so

扩展使用

[root@bogon hello]#  ls

会有一个 hello.php  文件

[root@bogon tests]# cat test.php
<?php echo hello();
echo "\r\n"; [root@bogon tests]# php test.php
hello word

输出了 hello word

此文转载于  原连接 http://www.djhull.com/phpext/php-ext-1.html

  • 请尊重本人劳动成功,可以随意转载但保留以下信息
  • 作者:岁月经年
  • 时间:2016年03月

php扩展开发1--添加函数的更多相关文章

  1. php扩展开发-函数

    我们首先找到快速上手文章里面关于函数定义的代码,以此说明然后开发PHP的函数 //php_myext.h PHP_FUNCTION(myext_hello);//函数申明,所有在myext.c文件定义 ...

  2. PHP扩展开发相关总结

    1.线程安全宏定义 在TSRM/TSRM.h文件中有如下定义 #define TSRMLS_FETCH() void ***tsrm_ls = (void ***) ts_resource_ex(0, ...

  3. Chrome扩展开发之一——Chrome扩展的文件结构

    目录: 0.Chrome扩展开发(Gmail附件管理助手)系列之〇——概述 1.Chrome扩展开发之一——Chrome扩展的文件结构 2.Chrome扩展开发之二——Chrome扩展中脚本的运行机制 ...

  4. php扩展开发初探

    2015年2月26日 15:44:41 原因: 想用PHP实现一个布隆过滤器算法, 其中要用到位运算, 但是PHP的内置的int类型不给力, 不能支持大整数的位运算 数据一旦太大, 就会变为浮点数表示 ...

  5. ios怎样实现快速将显卡中数据读出压缩成视频在cocos2dx扩展开发中

    如果解决ios怎样实现快速将显卡中数据读出压缩成视频在cocos2dx扩展开发中 手机平台性能是个关键问题. 压缩视频分成3个步骤: 读取显卡数据, 使用编码器压缩,保存文件. 使用libav 压缩的 ...

  6. PHP扩展开发01:第一个扩展【转】

    我们先假设业务场景,是需要有这么一个扩展,提供一个叫ccvita_string的函数,他的主要作用是返回一段字符.(这个业务场景实在太假,大家就这么看看吧)对应的PHP代码可能是这样: functio ...

  7. centos php扩展开发流程

    原文:centos php扩展开发流程 一.安装php centos 默认 yum 安装 php 版本为 5.3, 很多php框架基本上要求5.4以上版本,这时候不能直接 用 yum install ...

  8. ArcGIS 10.1 for Server 扩展开发(SOE)

    原文连接:http://blog.csdn.net/arcgisserver_book/article/details/7869368 第一章为什么使用SOE 在ArcGIS 10.1中ArcGIS ...

  9. PHP扩展开发-简单类扩展

    今天来学习简单类扩展开发 实现目标为如下php的类 <?php class classext(){ private $username; CONST URL="http://www.g ...

随机推荐

  1. Web应用程序与Web网站及部署在IIS中

    在Visual Studio可以创建 Web 应用程序项目或网站项目.通过选择 新建项目 或 打开项目 创建或打开一个 Web 应用程序项目在Visual Studio 文件 菜单. 通过选择 新建网 ...

  2. C# 自定义exe引用的dll路径

    MSDN原文:https://msdn.microsoft.com/library/twy1dw1e(v=vs.100).aspx <runtime> 的 <assemblyBind ...

  3. ACM学习历程—TopCoder SRM691 Div2

    这是我的第一次打TC,感觉打的一般般吧.不过TC的题目确实挺有意思的. 由于是用客户端打的,所以就不发题目地址了. 300分的题: 这题大意是有一段序列只包含+和数字0~9. 一段序列的操作是,从头扫 ...

  4. 十四、python沉淀之路--文件操作

    一.文件操作b模式 1. # f = open('test11.py','rb',encoding='utf-8') # 这种情况会报错 f = open('test11.py','rb') # b ...

  5. c&c++ datetime

    时间函数之间的关系 struct tm { int tm_sec; // 代表目前秒数,正常范围0-59,但允许至61秒: int tm_min; // 代表目前分数,范围为0-59. int tm_ ...

  6. 使用axis2进行webservice发布与调用

    一.介绍下cxf.axis.axis2区别 新一代的Web Services 框架如Axis2.CXF 都是由现有的项目中逐渐演化而来的,Axis2 是由大家熟悉的Axis 1.x 系列演化过来,而A ...

  7. 初上dubbo

    编译异常 no groovy library is defined for module http://blog.csdn.net/lu_wei_wei/article/details/7601968 ...

  8. Linux 输入子系统 input

    一.输入子系统 针对输入设备设计:触摸屏.键盘.按键.传感器.鼠标...... 二.每种设备都属于字符设备驱动,程序的写法步骤也相同 1.实现入口函数 xxx_init() 和卸载函数 xxx_exi ...

  9. android中MediaPlayer类的用法

    用法直接看sample package com.turtle920.androidaudioprocess; import android.media.MediaPlayer; import andr ...

  10. FPGA前世今生(一)

    关于FPGA,我想做硬件的或多或少都听过.从上世纪80年代算来,FPGA已走过了30多个年头.我们以FPGA两大生产厂商,两大巨头之一的INTEL(altera)公司的FPGA为例,为大家逐步介绍FP ...