工作原理就是把你写好的 php 代码编译成 c,然后你可以将其以扩展.so的形式添加到 'php.ini' 文件中。功能稍微少一点,适合简单场景
安装
git clone https://github.com/phalcon/zephir
cd zephir
./install -c
验证是否安装正确:
zephir help
开始编写代码
zephir init utils
执行之后,一个目录称为“utils”创建在当前工作目录:
$ cd utils
$ ls
ext/ utils/ config.json
utils/utils/greeting.zep
namespace Utils;
class Greeting
{
public static function say()
{
echo "hello world!";
}
}
现在,我们需要告诉Zephir编译和生成的扩展,必须在根目录:
zephir build
如果一切顺利将看到以下输出:
Extension installed!
Add extension=utils.so to your php.ini
Don't forget to restart your web server
最后添加到php扩展。 php.ini中加入extension=utils.so。
检查是否正常加载扩展通过执行以下:
$ php -m
[PHP Modules]
utils
测试
<?php
echo Utils\Greeting::say(), "\n";