美文网首页文章大全
PHP7编译安装ICE

PHP7编译安装ICE

作者: 殷临风 | 来源:发表于2017-05-25 10:50 被阅读806次

    ICE是一个跨语言, 跨平台的RPC框架, 一般公司也使用较多, 除了开源之外, 文档健全也是它能够被大家接受的一个重要原因. 对于java, python, nodejs等语言来讲, 使用ICE是一件非常容易的事情, 只需要引入相关的包, 而对于PHP来讲, 就不是那么简单了, 特别是高版本的PHP, 官方的yum安装不支持5.4以上的版本, 所以这个时候, 只能自己动手编译安装了

    1. 引入ice开发相关的yum源
    # 进入yum源目录, 下载ICE相关的yun源
    cd /etc/yum.repos.d
    
    # centos 6 (只能选择其中之一) 
    wget https://zeroc.com/download/rpm/zeroc-ice-el6.repo
    
    # centos 7
    wget https://zeroc.com/download/rpm/zeroc-ice-el7.repo
    
    2. 安装相关依赖
    yum install gcc-c++ 
    yum install mcpp-devel
    yum install libdb-cxx-devel
    yum install openssl-devel
    yum install bzip2-devel
    yum install expat-devel
    
    3. 安装php相关模块
    # CentOS 6.x 源 (只能选择其中之一) 
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
    
    # CentOS 7.x 源
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    
    yum install php70w php70w-devel
    
    4. 下载ice源码,编译安装
    # 下载源码
    cd /opt
    yum install git -y
    git clone -b 3.6 https://github.com/zeroc-ice/ice.git
    
    # 编译ice c++模块
    cd /opt/ice/cpp
    make # 时间会很久
    make install # 会在/opt/目录下生成新的文件夹 Ice-3.6.3
    
    # 编译ice php模块
    cd /opt/ice/php
    make
    make install
    

    如果出现找不到INT64_MAXINT64_MIN的错误, 最简单的做法就是修改php源码

    cd /usr/include/php/Zend
    

    将下面文件中两个变量类型的 64 都去掉, 如下图所示

    5. 配置php扩展
    # 查看php扩展文件存放的目录
    php -i | grep extension_dir
    # 假设在/usr/lib64/php/modules/路径下
    cp /opt/Ice-3.6.3/php/IcePHP.so /usr/lib64/php/modules/
    
    # 添加ice.ini
    cd /etc/php.d
    vi ice.ini
    
    # 添加如下内容
    ;Enable ice extension module
    extension=IcePHP.so
    
    # 检测php模块加载情况, 会发现有些*.so.36文件找不到
    php -m
    
    # 添加lib到全局
    echo "/opt/Ice-3.6.3/lib64" > /etc/ld.so.conf.d/ice-x86_64.conf
    # 使之生效
    ldconfig
    
    # 再次检测, 发现ice已经添加上了
    php -m
    

    除此之外, 还需要检测php web服务是否加载

    6. 使用ICE
    # 在调用的ice文件中引入加载文件路径
    ini_set('include_path',ini_get('include_path') . PATH_SEPARATOR . '/opt/Ice-3.6.3/php');
    require 'Ice.php'; // Load the core Ice run time definitions.
    require 'yinnote.php';
    
    $proxy_url = "printerClient -e 1.0:tcp -h yinnote.com -p 10002";
    
    $ic = null;
    try
    {
        $ic = Ice_initialize();  
        $base = $ic->stringToProxy($proxy_url);
        $printer = PrintServer_PrintinterfacePrxHelper::checkedCast($base);
    
        if(!$printer)
            throw new RuntimeException("Invalid proxy");
    
        echo $printer->printHelloWorld();
    }
    catch(Exception $ex)
    {
        echo $ex;
    }
    
    if($ic)
    {
        // Clean up
        try
        {
            $ic->destroy();
        }
        catch(Exception $ex)
        {
            echo $ex;
        }
    }
    </code>
    

    相关地址

    # 编译安装配置地址
    https://github.com/zeroc-ice/ice/blob/3.6/php/BuildInstructionsLinuxOSX.md
    # 源代码Git下载地址
    https://github.com/zeroc-ice/ice.git

    相关文章

      网友评论

        本文标题:PHP7编译安装ICE

        本文链接:https://www.haomeiwen.com/subject/tebaxxtx.html