在Windows下為PHP安裝redis擴充套件

2021-09-19 13:22:09 字數 4424 閱讀 1654

在安裝xdebug到時候你會有有ts和nts版本的選擇,在以前還有vc6和vc9的版本。如果你沒有根據你目前的伺服器的狀況選擇對應的版本的話,那麼xdebug是安裝不成功的。

一、如何選擇 php5.3 的 vc9 版本和 vc6 版本

vc6 版本是使用 visual studio 6 編譯器編譯的,如果你的 php 是用 apache 來架設的,那你就選擇 vc6 版本。

vc9 版本是使用 visual studio 2008 編譯器編譯的,如果你的 php 是用 iis 來架設的,那你就選擇 vc9 版本。

二、如何選擇 php5.3 的 thread safe 和 non thread safe 版本

先從字面意思上理解,thread safe 是執行緒安全,執行時會進行執行緒(thread)安全檢查,以防止有新要求就啟動新執行緒的 cgi 執行方式而耗盡系統資源。non thread safe 是非執行緒安全,在執行時不進行執行緒(thread)安全檢查。

再來看 php 的兩種執行方式:isapi 和 fastcgi。

isapi 執行方式是以 dll 動態庫的形式使用,可以在被使用者請求後執行,在處理完乙個使用者請求後不會馬上消失,所以需要進行執行緒安全檢查,這樣來提高程式的執行效率,所以如果是以 isapi 來執行 php,建議選擇 thread safe 版本;

而 fastcgi 執行方式是以單一執行緒來執行操作,所以不需要進行執行緒的安全檢查,除去執行緒安全檢查的防護反而可以提高執行效率,所以,如果是以 fastcgi 來執行 php,建議選擇 non thread safe 版本。

注:isapi 和 fastcgi無需在php中設定,是webserver的操作。

通過phpinfo();檢視當前php是什麼版本,thread safety,這個引數是檢視是否是執行緒安全。

我的php是5.2的執行在apache上,通過phpinfo發現thread safety是enabled的,所以我選擇了vc6非執行緒安全的版本安裝。在windows下的php.ini增加以下配置即可

[xdebug]

zend_extension_ts="d:/program files/php-5.2.13-win32/ext/php_xdebug-2.2.3-5.2-vc9.dll"

;是否開啟自動跟蹤

xdebug.auto_trace = on

;是否開啟異常跟蹤

xdebug.show_exception_trace = on

;是否開啟遠端除錯自動啟動

xdebug.remote_autostart = on

;是否開啟遠端除錯

xdebug.remote_enable = on

;允許除錯的客戶端ip

xdebug.remote_host=127.0.0.1

;遠端除錯的埠(預設9000)

xdebug.remote_port=9000

;除錯外掛程式dbgp

xdebug.remote_handler=dbgp

;是否收集變數

xdebug.collect_vars = on

;是否收集返回值

xdebug.collect_return = on

;是否收集引數

xdebug.collect_params = on

;跟蹤輸出路徑

xdebug.trace_output_dir="d:\xdebug\trace_output_dir"

;是否開啟除錯內容

xdebug.profiler_enable=on

;除錯輸出路徑

xdebug.profiler_output_dir="d:\xdebug\profiler_output_dir"

1.檢視自己的php版本

echo phpinfo();
php 版本資訊:

php logo

php version 5.3.29

compiler msvc9 (visual c++ 2008)

architecture x86

zend extension build api220090626,nts,vc9

php extension build api20090626,nts,vc9

2.根據php版本號,編譯器版本號和cpu架構,

這裡的php版本為5.6,x86,vc11 編譯的,所以,選下面的擴充套件版本:

選擇php_redis-2.2.7-5.3-nts-vc9-x86.zip和php_igbinary-1.2.1-5.3-nts-vc9-x86.zip

redis : 

igbinary: 

3.解壓縮後,將php_redis.dll和php_igbinary.dll拷貝至php的ext目錄下

4.修改php.ini,在該檔案中加入:

; php_redis

extension=php_igbinary.dll

extension=php_redis.dll

注意:extension=php_igbinary.dll一定要放在extension=php_redis.dll的前面,否則此擴充套件不會生效

<?php

//連線本地的 redis 服務

$redis = new redis();

$redis->connect('127.0.0.1', 6379);

echo "connection to server sucessfully";

//檢視服務是否執行

echo "server is running: " . $redis->ping();

?>

執行指令碼,輸出結果為:

connection to server sucessfully

server is running: pong

<?php

//連線本地的 redis 服務

$redis = new redis();

$redis->connect('127.0.0.1', 6379);

echo "connection to server sucessfully";

//設定 redis 字串資料

$redis->set("tutorial-name", "redis tutorial");

// 獲取儲存的資料並輸出

echo "stored string in redis:: " . $redis->get("tutorial-name");

?>

執行指令碼,輸出結果為:

connection to server sucessfully

stored string in redis:: redis tutorial

<?php

//連線本地的 redis 服務

$redis = new redis();

$redis->connect('127.0.0.1', 6379);

echo "connection to server sucessfully";

//儲存資料到列表中

$redis->lpush("tutorial-list", "redis");

$redis->lpush("tutorial-list", "mongodb");

$redis->lpush("tutorial-list", "mysql");

// 獲取儲存的資料並輸出

$arlist = $redis->lrange("tutorial-list", 0 ,5);

echo "stored string in redis";

print_r($arlist);

?>

執行指令碼,輸出結果為:

connection to server sucessfully

stored string in redis

redis

mongodb

mysql

<?php

//連線本地的 redis 服務

$redis = new redis();

$redis->connect('127.0.0.1', 6379);

echo "connection to server sucessfully";

// 獲取資料並輸出

$arlist = $redis->keys("*");

echo "stored keys in redis:: ";

print_r($arlist);

?>

執行指令碼,輸出結果為:

connection to server sucessfully

stored string in redis::

tutorial-name

tutorial-list

在Windows下為PHP安裝redis擴充套件

1.檢視自己的php版本echo phpinfo php 版本資訊 php logo php version 5.6.15 compiler msvc11 visual c 2012 architecture x86 zend extension build api220131226,ts,vc11...

在Windows下為PHP安裝redis擴充套件

一.php安裝redis擴充套件 1.使用phpinfo 函式檢視php的版本資訊,這會決定擴充套件檔案版本 2.根據php版本號,編譯器版本號和cpu架構,選擇php redis 2.2.5 5.6 ts vc11 x64.zip和php igbinary 1.2.1 5.5 ts vc11 x6...

在Windows下為PHP安裝redis擴充套件

1.檢視自己的php版本 echo phpinfo php 版本資訊 php logo php version 5.6.15 compiler msvc11 visual c 2012 architecture x86 zend extension build api220131226,ts,vc1...