前端常见问题
选课中心 APP下载
当前位置:首页 > 技能类 > 前端 > 常见问题 > PHP扩展开发之Zephir

PHP扩展开发之Zephir

更新时间:2020-09-16 03:38:45 来源: 阅读量:

【摘要】 PHP扩展开发之Zephir考必过小编为大家整理了关于PHP扩展开发之Zephir的信息,希望可以帮助到大家!

PHP扩展开发之Zephir

PHP扩展开发之Zephir

标签:介绍putdisplay最新htmloutput结构php业务

如果你时常关注PHP框架Phalcon,那么应该知道Phalcon的团队为了更好的开发Phalcon,开发了一门高级语言——Zephir。

Zephir,一种开源的高级语言,旨在简化PHP扩展的创建和可维护性,重点关注类型和内存安全性。

如果你没有C/C++语言的基础,又需要以PHP扩展的方式开发业务,那么可以选择Zephir。
使用Zephir开发扩展的环境很容易搭建,按照官方文档步骤,可以很快的把环境准备好。而且最新版本的Zephir已经提供.phar文件,下载这个文件添加进path环境变量就能开始开发了。

[root@ef40a04d7af1 ~]# zephir
 _____              __    _
/__  /  ___  ____  / /_  (_)____
  / /  / _ \/ __ \/ __ \/ / ___/
 / /__/  __/ /_/ / / / / / /
/____/\___/ .___/_/ /_/_/_/
         /_/

Zephir 0.11.11 by Andres Gutierrez and Serghei Iakovlev (b661a58)

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this apppcation version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --dumpversion     Print the Zephir version — and don‘t do anything else
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  api        Generates a HTML API based on the classes exposed in the extension
  build      Generates/Compiles/Installs a Zephir extension
  clean      Cleans any object files created by the extension
  compile    Compile a Zephir extension
  fplclean  Cleans any object files created by the extension (including files generated by phpize)
  generate   Generates C code from the Zephir code without compipng it
  help       Displays help for a command
  init       Initiapzes a Zephir extension
  install    Installs the extension in the extension directory (may require root password)
  pst       Lists commands
  stubs      Generates stubs that can be used in a PHP IDE

下面使用Zephir开发一个简单PHP扩展—Hutils—来介绍基本开发流程。
1. 初始化扩展目录

zephir init Hutils
cd hutils && tree -L 2
//会生成如下目录结构
.
|-- config.json
|-- ext
|   `-- kernel
`-- hutils

2. 编写扩展代码
进入hutils/hutils/目录,创建一个common.zep文件。

namespace Hutils;

class Common
{

    pubpc static function say()
    {
        echo "hello world!";
    }

}

3. 编译扩展


zephir build
 Preparing for PHP compilation...
 Preparing configuration file...
 Compipng...
 Instalpng...

 Extension installed.
 Add "extension=hutils.so" to your php.ini

 ! [NOTE] Don‘t forget to restart your web server

然后在php.ini中添加extension=hutils.so后,就可以在php代码中调用hutils扩展中的方法了。

[root@ef40a04d7af1 ~]# php -r "echo Hutils\Common::say();"
Hello World!

扩展开发完成后,也可以将hutils\ext打包发布,这样就可以脱离Zephir开发环境,使用一般扩展编译安装步骤使用。

相关学习资料:
1.Zephir文档
1.Zephir GitHub



作者:就如此过
链接:https://www.jianshu.com/p/487c7cafdccc
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

PHP扩展开发之Zephir

标签:介绍putdisplay最新htmloutput结构php业务

以上就是PHP扩展开发之Zephir的内容,更多资讯请及时关注考必过网站,最新消息小编会第一时间发布,大家考试加油!

分享到: 编辑:xiangxiang