-
- #tar -zxvf ./eaccelerator-0.9.5-beta2.tar.bz2
- #cd eaccelerator-0.9.5-beta2
- ="/usr/local"(把PHP安裝目錄匯入到環境變量,FreeBSD預設為/usr/local)
- #$PHP_PREFIX/bin/phpize
- #./configure --enable-eaccelerator=shared - -with-php-config=$PHP_PREFIX/bin/php-config
- #make
- #make install
複製程式碼
4、ini檔案配置
安裝完成,以下開始設定php.ini檔,eAccelerator提供了兩種設定和呼叫方式,分別如下。
安裝為 Zend extension 模式:
-
- #mkdir /tmp/eaccelerator
- #chmod 777 /tmp/eaccelerator
-
> 5、驗證安裝結果
透過瀏覽器存取您的phpinfo()頁面或執行 php -i 得到php配置訊息,裡面如果看到類似下面的資訊就表示安裝成功了。
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
with eAccelerator v0.9.5-beta2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
我的機器上同時也安裝了Zend Optimizer3.0.1,所以看到的資訊如下:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
with eAccelerator v0.9.5-beta2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
with Zend Extension Manager v1.0.10, Copyright (c) 2003-2006, by Zend Technologies
with Zend Optimizer v3.0.1, Copyright (c) 1998-2006, by Zend Technologies
如果你開啟了eAccelerator的debug選項,可以從日誌中看到類似下面的資訊
eaccelerator_lock("count");- eaccelerator_put("count",eaccelerator_get("count") 1));
- ?>
-
-
複製程式碼
eaccelerator_unlock($key)
根據 $key 釋放鎖
eaccelerator_cache_output($key, $eval_code, $ttl=0)
將 $eval_code 程式碼的輸出快取 $ttl 秒,($ttl參數同 eacclerator_put)
例如:
eaccelerator_cache_result($key, $eval_code, $ttl=0)
將 $eval_code 程式碼的執行結果快取 $ttl 秒,($ttl參數同 eacclerator_put),類似 cache_output
例如:
eaccelerator_cache_page($key, $ttl=0)
將目前整頁快取 $ttl 秒。
例如:
eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GEGET),30);- echo time();
- phpinfo();
- ?>
-
-
複製程式碼
eaccelerator_rm_page($key)
刪除由 eaccelerator_cache_page() 執行的緩存,參數也是 $key
2、php程式碼中使用eAccelerator加速
測試下eAccelerator強大的威力:(程式碼在 cli 模式下可能無效)
class test_cache {
- var $pro = 'hello';
function test_cache() {
- echo "Object Created!
n";
- }
- function func() {
- echo ', the world!';
- }
- function now($t) {
- echo date('Y-m-d H:i:s', $t);
- }
- }
$tt = eaccelerator_get("test_tt");
- if (!$tt)
- {
- $tt = new test_cache;
- eaccelerator_put("test_tt", $tt);
- echo "no cached!
n";
- }
- else {
- echo "cached
n";
- }
echo $tt->pro;
- $tt->func();
- $tt->now(time() 86400);
- ?>
-
-
-
-
複製程式碼
另外,據說在著名的vBulletin 3.60Beta版裡面已經整合了對eAccelerator的支援。
一段來自vBulletin裡面的程式碼
-
-
// ###############
- // ecelerator
/**
- * 用於從eAccelerator 取得和初始化vBulletin 資料儲存的類別
- *
- * @package vBulletin
- * @version $Revision: 0.1 $
- * @date $Date: 2005/06 /12 13:14:18 $
- */
- class vB_Datastore_eAccelerator extends vB_Datastore
- {
- /**
- * 從 eAccelerator 取得資料儲存的內容
- *
- * @param array 要從資料儲存中取得的項目陣列
- *
- * @return void
- */
- function fetch($itemarray) if (!function_exists('eaccelerator_get'))
- {
- trigger_error("eAccelerator not installed", E_USER_ERROR);
- }}
- defaultitems AS $item)
- {
- $this->do_fetch($item);
- }
if (is_array($itemarray))
- {
- foreach ($itemarray AS $item)
- {
- $this->do_fetch($item);
- }
- }
$this->check_options( );
// set the version number variable
- $this->registry->versionnumber =& $this->registry->options['templateversion'];
- }
/**
- * 從共享記憶體取得資料並偵測錯誤
- *
- * @param string 資料儲存項目的標題
- *
- * @return void
- */
- function do_fetch($title)
- {
- $data = eaccelerator_get($title);
- if ($data === null)
- { // appears its not there, lets grab the data, lock the shared memory and put it in
- $data = '';
- $dataitem = $this->dbobject-$data = '';
- $dataitem = $this->dbobject-$data = '';
- $dataitem = $this->dbobject-$data = '';
- $dataitem = $this->dbobject- >query_first("
- SELECT title, data FROM " . TABLE_PREFIX . "datastore
- WHERE title = '" . $this->dbobject->escape_string($title) ."'
- ")'
- "); >if (!empty($dataitem['title']))
- {
- $data =& $dataitem['data'];
- $this->build($dataitem['title'] , $dataitem['data']);
- }
- }
- $this->register($title, $data);
- }
- /**
- * 更新對應的快取檔案
- *
- * @param string 資料儲存項目的標題
- *
- * @return void
- */
- function build($title, $data)
- {
- if (!function_exists('eaccelerator_put'))
- {
- trigger_error("eAccelerator not installed, Enot);
- eaccelerator_lock($title);
- eaccelerator_put($title, $data);
- eaccelerator_unlock($title);
- }
- }
> 複製程式碼
|