欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

快速开发一个PHP扩展

程序员文章站 2022-04-29 19:05:22
...
本文通过非常快速的方式讲解了如何制作一个PHP 5.2 环境的扩展(PHP Extension),希望能够在图文的方式下让想快速学习的朋友了解一下制作过程。

需求:比如开发一个叫做 heiyeluren 的扩展,扩展里就一个函数 heiyeluren_test(),输入一个字符串,函数返回:Your input string: xxxxx。

要求:了解C/C++编程,熟悉PHP编程

环境:下载一份php对应版本的源码,我这里是 php-5.2.6,先正常安装php,假设我们的php安装在 /usr/local/php 目录,源码在 /root/soft/php/php-5.2.6/,现在开始!

步骤一:生成扩展框架

cd /root/soft/php/php-5.2.6/ext

./ext_skel --extname=heiyeluren

cd /root/soft/php/php-5.2.6/ext/heiyeluren

vi config.m4

打开文件后去掉 dnl ,获得下面的信息:

PHP_ARG_ENABLE(heiyeluren, whether to enable heiyeluren support,

[ --enable-heiyeluren Enable heiyeluren support])

保存退出.