最简单快速的队列服务器

字体大小: 中小 标准 ->行高大小: 标准
今天使用redis做队列服务器,兼职是太快了 出奇的快速稳定,rhel 和centos5 安装超级简单.
安装过程
1.安装定制源
  安装#rpm -Uvhhttp://os.69hn.com/custom.rpm 

2.安装redis
# yum -yinstall redis

3. 启动:
#service redis start

接着安装php的下redis的扩展包,
#yum -y install php-redis

入队列操作文件 list_push.php

<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
while (true) {
    $redis->lPush('list1', 'A_'.date('Y-m-d H:i:s'));
    sleep(rand()%3);
}
?>

执行# php list_push.php &

出队列操作 list_pop.php文件
<?php
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);
while(true) {
    try {
        var_export( $redis->blPop('list1', 10) );
    } catch(Exception $e) {
        //echo $e;    
    }
}
就是这么简单的一段代码,就搞定了

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/30003.html