本文實(shí)例講述了PHP7安裝Redis擴(kuò)展的方法。分享給大家供大家參考,具體如下:
linux中PHP7安裝Redis擴(kuò)展
1.依次執(zhí)行
1
2
3
4
5
6
7
|
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擴(kuò)展
這里提供php5.3版本的redis的php擴(kuò)展壓縮包(里面有個(gè)dll):https://github.com/nicolasff/phpredis/downloads
解壓后把dll放到php的ext目錄下,打開php.ini,增加一行:
1
|
extension=php_redis.dll |
然后重啟apache即可
例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?php //獲取投票的信息的ID $aid = isset( $_GET [ 'aid' ]) ? ereg_replace ( "[^0-9]" , "" , $_GET [ 'aid' ]) : 0; //當(dāng)前投票的數(shù)字,指的是在redis中的數(shù)據(jù) $this_click_num = 0; if ( $aid >2){ //設(shè)定寫回的投票數(shù)的最大值,到了此值就寫回mysql $update_till_num = 50; //創(chuàng)建redis對(duì)象 $r = new Redis(); $r ->connect( '127.0.0.1' ,6379); //得到現(xiàn)在是第幾個(gè)數(shù)據(jù)了 $this_click_num = $r ->get( 'count_xin_newgame:' . $aid ); //點(diǎn)擊數(shù)加1 $r ->set( 'count_xin_newgame:' . $aid , $this_click_num +1); if ( $this_click_num >= $update_till_num ) { //如果點(diǎn)擊數(shù)超過了設(shè)定數(shù),那么就把數(shù)據(jù)寫到mysql if ( $this_click_num > $update_till_num ) require_once (dirname( __FILE__ ). "/db.php" ); //更新數(shù)據(jù)庫 $db ->ExecuteNoneQuery( "UPDATE `addonnewgame` SET `game_num` = game_num + '{$update_till_num}' WHERE `dede_addonnewgame`.`aid` ={ $aid };" ); //重置投票數(shù)目為0 $r ->set( 'count_xin_newgame:' . $aid ,0); } $r ->setTimeout( 'count_xin_newgame:' . $aid ,7*24*60*60); exit ( $this_click_num ); } ?> |
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。