zoukankan      html  css  js  c++  java
  • Zephir入门教程一

    一、如何安装

     zephir-安装和初体验:http://blog.csdn.net/u011142688/article/details/51619811

    二、如何使用

    需要切到工作目录下,也就是converted下,开始编写代码,新建一个文件夹converted,在该文件下执行命令:

    zephir init openresty

     

    进入openresty 目录修改json文件

    /mnt/hgfs/Linux-Share/thinkphp5-study-line/converted/openresty$ vim config.json 
    "description": "php openresty extend", "author": "Tinywan",

    当前目录文件

    进入Openresty 目录新建文件 redis.zep

    namespace Openresty;
    class Redis
    {
        public static function init()
        {
            echo "hello Openresty !";
        }
    }

    目录结构

     

     现在,需要告诉Zephir把我们的项目编译成扩展,这一步要在项目目录下执行:zephir build (要切换到:/mnt/hgfs/Linux-Share/thinkphp5-study-line/converted/openresty 目录下)

    编译好的扩展文件在那里来?

    修改PHP配置文件:sudo vim /opt/php-7.0.9/etc/php.ini

    添加内容:extension=/mnt/hgfs/Linux-Share/thinkphp5-study-line/converted/openresty/ext/modules/openresty.so

    重启Nginx和php-fmp 服务器,查看配置信息,以下表示编译成功了

    public function test(){
        phpinfo();
    }

     

    如何使用?

    public function Openresty(){
        echo OpenrestyRedis::init(), "
    ";
        echo "Openresty";
    }

     三、遇到的错误

    以下是在非root目录下运行的,所以要切换到root下运行就没问题; 

    tinywan@tinywan:~/PHP7/zephir/converted/utils/utils$ zephir build 
    ZephirException: Extension namespace cannot be loaded
  • 相关阅读:
    Generate Parentheses
    Length of Last Word
    Maximum Subarray
    Count and Say
    二分搜索算法
    Search Insert Position
    Implement strStr()
    Remove Element
    Remove Duplicates from Sorted Array
    Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/tinywan/p/7117309.html
Copyright © 2011-2022 走看看