Commit c90a2a90 authored by chenchuanwen's avatar chenchuanwen

bridgestart

parent 57371f7f
......@@ -94,7 +94,20 @@ class Common
}
return false;
}
public static function redisPublish($control,$method,$params){
//发布application.redis.redisPublishName
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
$redisPublishName=\Yaf\Registry::get('config')->get('redis.redisPublishName');
$redis=new Redis();
$redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){
$redis->auth($conf['password']);
}
$message=array($control,$method,$params);
$message=json_encode($message);
$ret=$redis->publish($redisPublishName,$message);
return $ret;
}
/**
* 获取客户端IP
*
......
......@@ -1638,6 +1638,7 @@ class OrderServiceModel extends \Business\AbstractModel
}
public function testPush($msg){
echo $msg.'abcde';
return true;
}
/**
* 类实例
......
......@@ -12,6 +12,8 @@ application.dispatcher.catchException = true
; Admin模块用于后台管理
application.modules = Index,Api,Admin,Client
redis.redisPublishName='redisPublish';
[productone : common]
; 数据库配置
resources.database.params.driver = "pdo_mysql"
......
......@@ -4,12 +4,13 @@ require APPLICATION_PATH . '/scripts/crontab/baseCli.php';
require APPLICATION_PATH . '/scripts/crontab/common.php';
error_reporting(E_ALL ^ E_NOTICE);
//发布
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
$redis=new Redis();
$redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){
$redis->auth($conf['password']);
}
$message=array('abd','happy New Year');
$message=json_encode($message);
$ret=$redis->publish('redisPublish',$message);
//$conf = \Yaf\Registry::get('config')->get('redis.database.params');
//$redis=new Redis();
//$redis->connect($conf['host'], $conf['port']);
//if(!empty($conf['password'])){
// $redis->auth($conf['password']);
//}
//$message=array('abd','happy New Year');
//$message=json_encode($message);
//$ret=$redis->publish('redisPublish',$message);
\Our\Common::redisPublish('\Business\Order\OrderServiceModel','testPush',array('happy New Year'));
......@@ -43,7 +43,26 @@ class runRedisPush
}
}
public function callback($instance,$channelName,$message){
echo json_encode($message);
try{
$message=json_decode($message,true);
$callInstance=$message['className']::getInstance(\Our\DbNameConst::masterDBConnectName);
echo $message."\r\n";
if(empty($message['params'])){
$res=call_user_func_array(array($callInstance,$message['method']),array());
}else{
$res=call_user_func_array(array($callInstance,$message['method']),$message['params']);
}
$res=(isset($res)&&!empty($res))?$res:false;
if($res!==false){
echo 'success'."\r\n";
}else{
echo 'fail1'."\r\n";
}
unset($callInstance);
\Mysql\LinkMySQLModel::unsetDbConecet();
}catch(Exception $ex){
echo $ex->getMessage();
}
// $orderService=\Business\Order\OrderServiceModel::getInstance();
// $orderService->testPush($message);
}
......@@ -59,6 +78,7 @@ class runRedisPush
{
$pid = $this->daemon();
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
$redisPublishName=\Yaf\Registry::get('config')->get('redis.redisPublishName');
$redis=new Redis();
$redis->connect($conf['host'], $conf['port']);
if(!empty($conf['password'])){
......@@ -66,7 +86,7 @@ class runRedisPush
}
//ini_set('default_socket_timeout', -1);(所有长连接不超时)
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
$result=$redis->subscribe(array('redisPublish'), array($this,'callback'));
$result=$redis->subscribe(array($redisPublishName), array($this,'callback'));
}
private function reload(){
......
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