<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/17 0017
 * Time: 下午 2:29
 */

function callback($instance,$channelName,$message){
    require APPLICATION_PATH . '/scripts/crontab/common.php';
    error_reporting(E_ALL ^ E_NOTICE);
    try{
        $message=json_decode($message,true);
        $callInstance=$message['className']::getInstance(\Our\DbNameConst::masterDBConnectName);
        echo json_encode($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();
    }
}
$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']);
}

//ini_set('default_socket_timeout', -1);(所有长连接不超时)
$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
$result=$redis->subscribe(array($redisPublishName), 'callback');