-
- #tar -zxvf ./eaccelerator-0.9.5-beta2.tar.bz2
- #cd eaccelerator-0.9.5-beta2
- #export PHP_PREFIX="/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($_GET),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里面的代码
-
-
// ##############
- // eAccelerator
/**
- * Class for fetching and initializing the vBulletin datastore from eAccelerator
- *
- * @package vBulletin
- * @version $Revision: 0.1 $
- * @date $Date: 2005/06/12 13:14:18 $
- */
- class vB_Datastore_eAccelerator extends vB_Datastore
- {
- /**
- * Fetches the contents of the datastore from eAccelerator
- *
- * @param array Array of items to fetch from the datastore
- *
- * @return void
- */
- function fetch($itemarray)
- {
- if (!function_exists('eaccelerator_get'))
- {
- trigger_error("eAccelerator not installed", E_USER_ERROR);
- }
foreach ($this->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'];
- }
/**
- * Fetches the data from shared memory and detects errors
- *
- * @param string title of the datastore item
- *
- * @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->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);
- }
- /**
- * Updates the appropriate cache file
- *
- * @param string title of the datastore item
- *
- * @return void
- */
- function build($title, $data)
- {
- if (!function_exists('eaccelerator_put'))
- {
- trigger_error("eAccelerator not installed", E_USER_ERROR);
- }
- eaccelerator_lock($title);
- eaccelerator_put($title, $data);
- eaccelerator_unlock($title);
- }
- }
-
复制代码
|