首先简单介绍下zephir 这个工具
他是phalcon提供的一个快速开发php扩展的工具,phalcon是一个丰富的php开发框架,纯C扩展哦(yaf知道吧,比yaf更庞大)。
官网 :
下载安装 :
To build a PHP extension and use Zephir you need the following requirements:
gcc >= 4.x/clang >= 3.x
re2c 0.13 or later
gnu make 3.81 or later
autoconf 2.31 or later
automake 1.14 or later
libpcre3
php development headers and tools
php 命令在终端可执行
第一步:下载
$ git clone
第二步:安装
$ cd zephir
$ ./install -c
第三步:测试
$ zephir help
第六步:php扩展demo
1. 创建一个文件夹,执行下面命令
zephir init poem
产生一个文件夹poem,文件夹下三个子文件config.jsonext/ poem/
2.编辑文件poem/ people .zep
cd poem
vim poem/people.zep
增加下面这段代码,输出hello poem
namespace Poem;
class People
{
public static function say()
{
var a = “hello poem”;
echo strtoupper(a);
}
}
这里的namespace是必须添加的,输出大写的”hello poem”。可以直接使用php的内置函数。然后执行编译
3. 构建扩展
zephir build
编译扩展成功
piledPreparing for PHP compilation…
Preparing configuration file…
Compiling…
Installing…
Extension installed!
Don’t forget to restart your web server
4. 编辑php. ini文件 下入下面代码
extension=poem.so
5. 编写一个测试文件test.php
<?php
echo Poem\People::say();
执行测试文件 php test.php 结果输出为
HELLO POEM
完美输出ok!