Heim  >  Artikel  >  Backend-Entwicklung  >  php扩展模块的安装和编写

php扩展模块的安装和编写

WBOY
WBOYOriginal
2016-07-25 08:46:23986Durchsuche

php扩展模块的安装和编写,有需要的朋友可以参考下。


1.PHP的源码安装(以php6为例)

从官网下载php6的源码,解压

进入解压之后的文件夹

./buildconf --force

./configure --prefix=/usr/local/php6 --enable-fpm

以上两行用来配置安装的信息,./表示使用当前目录下的程序,--prefix表示要安装到的目录

make 编译php源码

make install 安装

/usr/local/php6/bin -v 这个可以用来测试是否安装成功


2.PHP扩展模块安装

如何加载模块(pcntl为例)

cd 指令进入源码下的ext/pcntl文件夹

/usr/local/php6/bin/phpize phpize程序是用来加载一个扩展的程序,这里要使用需要加载扩展的那个php的phpize(如果你有多个php的话)

./configure--with-php-config=/usr/local/php6/bin/php-config 配置扩展模块的信息,之所以有后面的路径原因同上(选用需要加载扩展的那个php的配置),这里是为了让php和扩展模块的配置相同

make 编译

编译之后会在当前目录下的modules下面生成pcntl.so

把pcntl.so拷贝到php的安装目录(最好是在ext下)

修改php.ini(可以通过运行phpinfo(),搜索php.ini方法来找到这个文件,一般在lib下面,如果找到的那个路径没有php.ini就要自己新建一个)

在里面加上 extensions=pcntl.so的路径

然后就可以运行了


3.PHP自定义扩展模块

假设需要一个叫做computeDistance(positionX,positionY)的函数

编写distance.skel文件内容为

int computeDistance(int positionX,int positionY) 这个文件说明了我们需要什么样的模块

./ext_skel--extname=distance --proto=distance.skel

上面用ext_skel这个程序生成了整个模块的框架 两个参数分别为 模块的名字,模块的描述文件

进入刚生成的模块文件夹

修改config.m4

dnl PHP_ARG_WITH(ccvita, for ccvita support,

dnl Make sure that the comment is aligned:

dnl [ --with-distance Include distance support])

这三行前面的dnl删除

修改distance.c

找到PHP_FUNCTION这个函数把参数改成computeDistance ,也就是改成我们需要调用的函数的名字,自行修改函数内容

接下来的步骤和上面一样

phpize

./configure

make

复制

修改配置文件


php


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn