Commit 59880624 authored by chenchuanwen's avatar chenchuanwen

redispush

parent 125b3068
<?php
//发布
$redis = new Redis();
$redis->connect('192.168.1.201', 6379);
$message='happy New Year';
$ret=$redis->publish('pushcenter',$message);
<?php
//订阅
ini_set('default_socket_timeout', -1); //不超时
$redis = new Redis();
$redis->connect('192.168.1.201', 6379);
$result=$redis->subscribe(array('pushcenter'), 'callback');
function printTest($meg){
$len=10;
for($i=0;$i<$len;$i++){
sleep(1);
echo $meg."\r\n";
}
}
function callback($instance,$channelName,$message){
printTest($message);
}
<?php
/**
* 推送10秒推送一次
* 推送10秒推送一次
*
* @author chenjiebin <sjlinyu@qq.com>
*/
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require APPLICATION_PATH . '/scripts/crontab/baseCli.php';
require APPLICATION_PATH . '/scripts/crontab/common.php';
error_reporting(E_ALL ^ E_NOTICE);
$redis = new Redis();
$redis->connect('192.168.1.201', 6379);
$result=$redis->subscribe(array('pushcenter'), 'callback');
function printTest($meg){
echo $meg;
}
function callback($instance,$channelName,$message){
printTest($message);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment