-
- #tar -zxvf ./eaccelerator-0.9.5-beta2.tar.bz2
- #cd eaccelerator-0.9.5-beta2
- #export PHP_PREFIX="/usr/local" (Import the PHP installation directory to Environment variables, FreeBSD defaults to /usr/local)
- #$PHP_PREFIX/bin/phpize
- #./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
- #make
- #make install
Copy code
4. ini file configuration
After the installation is complete, let's start configuring the php.ini file. eAccelerator provides two configuration and calling methods, as follows.
Install in Zend extension mode:
-
- #mkdir /tmp/eaccelerator
- #chmod 777 /tmp/eaccelerator
-
Copy the code
5. Verify the installation results
Access your phpinfo() page through a browser or run php -i to get the PHP configuration information. If you see information similar to the following, the installation is successful.
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 is also installed on my machine, so the information I see is as follows:
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
If you turn on the debug option of eAccelerator, you can see information similar to the following in the log
-
- eaccelerator_lock("count");
- eaccelerator_put("count",eaccelerator_get("count")+1));
- ?>
Copy code
eaccelerator_unlock( $key)
Release lock based on $key
eaccelerator_cache_output($key, $eval_code, $ttl=0)
Cache the output of the $eval_code code for $ttl seconds (the $ttl parameter is the same as eacclerator_put)
For example:
eaccelerator_cache_result($key, $eval_code, $ttl=0)
Cache the execution result of the $eval_code code for $ttl seconds (the $ttl parameter is the same as eacclerator_put), similar to cache_output
For example:
eaccelerator_cache_page($key, $ttl=0 )
Cache the current full page for $ttl seconds.
For example:
-
- eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
- echo time();
- phpinfo();
- ?> ;
Copy code eaccelerator_rm_page($key)
Delete the cache executed by eaccelerator_cache_page(), the parameter is also $key
2. Use eAccelerator to accelerate PHP code
Test the powerful power of eAccelerator: (This code may not be valid in cli mode)
class test_cache { - var $pro = 'hello';
function test_cache() {
- echo "Object Created!< ;br>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);
- ?>
-
-
Copy code
In addition, it is said that support for eAccelerator has been integrated into the famous vBulletin 3.60Beta version.
A piece of code from 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);
- }
- }
-
Copy code
|