zoukankan      html  css  js  c++  java
  • 弹幕的产生

    /**
    * 产生弹幕数据
    * php index.php cli goods gen_barrage_data
    */
    public function gen_barrage_data()
    {
    $cache_key = CACHE_KEY_PREFIX . 'barrage';
    $cache_data = [];
    $s_time = time();
    $this->load->driver('cache', array('adapter' => 'memcached', 'backup' => 'file'));
    $this->load->model('member/member_go_record');
    $sleep_time = 1;
    while (true) {
    //超过一分钟退出程序
    if (time() - $s_time >= 60) {
    exit("到了一分钟的时间,结束此次进程");
    }
    //读取最新的购买记录的id
    $more_than_id = 0;
    if ($this->cache->get(CACHE_KEY_PREFIX . 'barrage_max_id')) {
    $more_than_id = $this->cache->get(CACHE_KEY_PREFIX . 'barrage_max_id');
    }
    //查询新的购买记录数据
    $barrage_data = $this->member_go_record->get_barrage_data($more_than_id);
    if (empty($barrage_data)) {
    echo "no new data ";
    sleep($sleep_time);
    continue;
    }

    //记录弹幕数据到缓存
    foreach ($barrage_data as &$v) {
    $tmp_ip = explode(',', $v['ip']);
    $v['ip'] = $this->deal_ip_address($tmp_ip[0]);
    }
    $old_barrage_data = $this->cache->get($cache_key);
    $old_barrage_data = json_decode($old_barrage_data, TRUE);
    if (!is_array($old_barrage_data)) {
    $old_barrage_data = [];
    }
    $barrage_data = array_merge($barrage_data, $old_barrage_data);
    $barrage_data = array_slice($barrage_data, 0, 10);
    $this->cache->save($cache_key, json_encode($barrage_data), TIME_HOUR);

    //记录最新的id到缓存
    $max_id = $barrage_data[0]['id'];
    var_dump($max_id);
    $this->cache->save(CACHE_KEY_PREFIX . 'barrage_max_id', $max_id, TIME_HOUR);
    sleep($sleep_time);
    }
    }
  • 相关阅读:
    算法14-----位运算操作(1)
    算法13------集合所有的子集或者字符串所有子串
    21、缓存设计
    20、内存溢出(Out of Memory)
    19、内容共享
    14、数据传输更省电
    15、自定义Content Provider
    16、编写适应多个API Level的APK
    17、屏幕适配,多语言支持,手机类型适配
    18、不同平台版本
  • 原文地址:https://www.cnblogs.com/da-guang/p/6374214.html
Copyright © 2011-2022 走看看