zoukankan      html  css  js  c++  java
  • Yar请求数据接口

        //[['u'=>'site.index','d'=>['a'=>2],'k'=>'test']];
        public function apiBatch($arr,$timeout=15000) {
            ini_set("yar.timeout",$timeout);
            $url = C('RPCURL');
            foreach ($arr as  $v){
                $k = $v['k'] ? $v['k']:$v['u'];
                $cacheKey = md5(http_build_query($v));
                if(!$v['t'] || !is_array($this->$k = S($cacheKey))){
                    Yar_Concurrent_Client::call($url."?key=".$k."|".$cacheKey, 'api', $v, [$this, "callback"]);
                }
            }
            Yar_Concurrent_Client::loop([$this, "callback"], [$this, "error_callback"]);
        }
        
        //['u'=>'site.index','d'=>[],'t'=>200] 缓存时间秒
        public function api($arr,$timeout=15000) {
            ini_set("yar.timeout",$timeout);
            $url = C('RPCURL');
            $cacheKey = md5(http_build_query($arr));
            $cacheTime = isset($arr['t']) ? $arr['t'] : 300;
            if(!$cacheTime || (!$result = S($cacheKey))){
                $client = new Yar_Client($url);
                $result = $client->api($arr['u'],$arr['d']);
                if($cacheTime && $result['data']){
                    S($cacheKey,$result,  $cacheTime);
                }
            }
            return $result;
        }
  • 相关阅读:
    mysql 索引
    redis持久化
    redis发布订阅
    django 信号
    paramiko模块
    23种设计模式python实现
    几种浏览器存储数据的方式
    关于传参
    对字符串里的四则运算进行计算2020/10/12
    动手动脑2020/10/9
  • 原文地址:https://www.cnblogs.com/mthp/p/9235051.html
Copyright © 2011-2022 走看看