• PHP基础组件-Zookeeper+MetaQ


    1.Zookeeper扩展安装

    wget http://mirror.bit.edu.cn/apache//zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz 
    tar –zxvf zookeeper-3.4.6.tar.gz 
    cd /usr/local/src/zookeeper-3.4.6/src/c 
    ./configure && make && make install 
    
    wget http://pecl.php.net/get/zookeeper-0.2.2.tgz 
    tar -zxvf zookeeper-0.2.2.tgz 
    cd zookeeper-0.2.2 
    /data/php/bin/phpize 
    ./configure --with-php-config=/data/php/bin/php-config 
    make && make install 
    
    vim /data/php/etc/php.ini 
    extension=zookeeper.so 
    #重启PHP即可

    2.消费MetaQ

    <?php
    require_once 'MetaQ.php';
    
    $metaqConfig['group'] = 'Flyme_BBS_TEST';
    $metaqConfig['topic'] = 'FlYME_USER_UC';
    $metaqConfig['config'] = array('zkHosts' => '172.16.200.239:2181,172.16.200.233:2181,172.16.200.234:2181');
    
    
    $metaq = new MetaQMetaQ($metaqConfig['config']);
    $metaq->subscribe($metaqConfig['topic'], $metaqConfig['group']);
    while (1) {
        $msgs = $metaq->getNext();
        foreach ($msgs as $msg) {
            print_r($msg);
            usleep(1000);
        }
    }
    ?>

    3.写MetaQ

    <?php
    require_once 'MetaQ.php';
    
    $metaqConfig['group'] = 'Flyme_BBS_TEST';
    $metaqConfig['topic'] = 'FlYME_USER_UC';
    $metaqConfig['config'] = array('zkHosts' => '172.16.200.239:2181,172.16.200.233:2181,172.16.200.234:2181');
    
    
    $metaq = new MetaQMetaQ($metaqConfig['config']);
    $metaq->initPartitionList($metaqConfig['topic']);
    
    $i = 0;
    while (++$i < 10000) {
        $result = $metaq->put('t1', 'hello' . $i);
        print_r($result);
        usleep(1000);
    }
    ?>
  • 相关阅读:
    vim
    Linux 软链接和硬链接
    常用命令
    linux 二级目录结构
    关于bash shell的理解
    虚拟机网络模式
    安装虚拟机
    date 命令
    使用3种协议搭建yum仓库
    ubuntu update时发生错误
  • 原文地址:https://www.cnblogs.com/appledady/p/9322736.html
Copyright © 2020-2023  润新知