PHP는 MySQL 데이터베이스와 Redis 통계를 운영합니다.

墨辰丷
풀어 주다: 2023-03-29 21:54:02
원래의
1331명이 탐색했습니다.

이 글은 주로 MySQL 데이터베이스의 PHP 동작과 Redis 통계를 소개합니다. 관심있는 친구들이 참고하시면 좋겠습니다.

자세한 내용은 다음과 같습니다.

<?php
  header("Content-Type:text/html;charset=utf-8");
  include &#39;lib/mysql.class.php&#39;;
  $mysql_obj = mysql::getConn();
  //redis 
  $redis = new Redis();
  $redis->pconnect(&#39;127.0.0.1&#39;, 6379);
  if(isset($_SERVER[&#39;HTTP_REFERER&#39;])){
    $url_md5 = md5($_SERVER[&#39;HTTP_REFERER&#39;]);
  }
  $adve_key = &#39;adve&#39;; 
  $adve_key_exists = &#39;adve_exists&#39;;
  if(!$redis->exists($adve_key_exists)){
    $list = $mysql_obj->fetch_array("select * from user_online_adve");
    if($list){
      foreach ($list as $key => $value) {
        $url_hash = md5($value[&#39;adve_url&#39;]);
        $adve_hash_key = $adve_key.":".$url_hash;
        $id = $value[&#39;id&#39;];
        $redis->set($adve_hash_key,$id);
        $redis->set($adve_key_exists,true);
        //$redis->hmset($adve_hash_key, array(&#39;id&#39; =>$id));
        //print_r($redis->get($adve_hash_key));
      }
    }
  }
  $adve_new_key = $adve_key.&#39;:&#39;.$url_md5;
  if($redis->exists($adve_new_key)){
      $adve_plus = $adve_new_key.":plus" ;
      if(!$redis->exists($adve_plus)){
        $redis->set($adve_plus,1); 
      }else{
        $redis->incr($adve_plus);
        $num = $redis->get($adve_plus);
        if($num >10){
          $id = $redis->get($adve_new_key);
          // insert to sql;
          $mysql_obj->query("update user_online_adve set adve_num=adve_num+$num where id=$id");
          $redis->set($adve_plus,1);
        }
      }
  }
  header(&#39;HTTP/1.0 301 Moved Permanently&#39;);
  header(&#39;Location: https://itunes.apple.com/cn/app/san-guo-zhi15-ba-wangno-da-lu/id694974270?mt=8&#39;);
/*
  if(){
      $adve_plus = $adve_key.":plus" ;
      if($redis->exists($adve_plus)){
        $redis->incr($adve_plus);
      }else{
        $redis->set($adve_plus,1); 
      }
      echo $redis->get($adve_plus);
  }
  foreach ($list as $key => $value) {
      $url_hash = md5($value[&#39;adve_url&#39;]);
      $id = $value[&#39;id&#39;];
      $adve_num = $value[&#39;adve_num&#39;];
      $adve_plus = $adve_key.":plus" ;
      if($redis->exists($adve_plus)){
        $redis->incr($adve_plus);
      }else{
        $redis->set($adve_plus,1); 
      }
      echo $redis->get($adve_plus);
      //if($redis->)
      //$redis->hmset($adve_key, array(&#39;id&#39; =>$id, &#39;adve_num&#39;=>$adve_num));
      //print_r($redis->hmget("adve:$url_hash", array(&#39;adve_num&#39;)));
  }
    print_r($list);
*/
로그인 후 복사

요약: 위 내용은 이 글의 전체 내용입니다. 모든 분들의 공부에 도움이 되었으면 좋겠습니다.

관련 권장 사항:

PHP는 컬

php WeChat 빨간 봉투 알고리즘

php 버블 정렬 및 빠른 정렬 알고리즘

을 기반으로 자동 응답 인터페이스를 호출합니다.

위 내용은 PHP는 MySQL 데이터베이스와 Redis 통계를 운영합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!