PHP7安裝Redis擴充的方法

來源:互聯網
上載者:User

linux中PHP7安裝Redis擴充

1.依次執行

wget -c https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zip

cd phpredis-php7
/YouPath/phpize
./configure --with-php-config=/YouPath/php-config
make
make install

2.加入php.ini
3.重啟httpd
4.查看探針

windowsPHP7安裝Redis擴充

這裡提供php5.3版本的redis的php擴充壓縮包(裡面有個dll):https://github.com/nicolasff/phpredis/downloads

解壓後把dll放到php的ext目錄下,開啟php.ini,增加一行:

extension=php_redis.dll

然後重啟apache即可

例子

<?php

//擷取投票的資訊的ID
$aid = isset($_GET['aid']) ? ereg_replace("[^0-9]", "", $_GET['aid']) : 0;

//當前投票的數字,指的是在redis中的資料
$this_click_num = 0;

if($aid>2){
 //設定寫回的投票數的最大值,到了此值就寫回mysql
 $update_till_num = 50;
 
 //建立redis對象
 $r = new Redis();
 $r->connect('127.0.0.1',6379);
 //得到現在是第幾個資料了
 $this_click_num = $r->get('count_xin_newgame:'.$aid);
 //點擊數加1
 $r->set('count_xin_newgame:'.$aid,$this_click_num+1);
 if($this_click_num>=$update_till_num)
 {
  //如果點擊數超過了設定數,那麼就把資料寫到mysql
  if($this_click_num>$update_till_num)
  require_once(dirname(__FILE__)."/db.php");
  //更新資料庫
  $db->ExecuteNoneQuery(
   "UPDATE `addonnewgame`
    SET `game_num` = game_num + '{$update_till_num}'
    WHERE `dede_addonnewgame`.`aid` ={$aid};"
  );
  //重設投票數目為0
  $r->set('count_xin_newgame:'.$aid,0);
 }
 $r->setTimeout('count_xin_newgame:'.$aid,7*24*60*60);
 exit($this_click_num);
}
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.