1, API and documentation description:
Eaccelerator provides a convenient, convenient and stable way to implement native caching, because most code implementations are based on shared memory, so they can only be used on the *nix platform, and Windows platform Michael is temporarily unaware of the time when this is supported.
Eaccelerator provides the following API interfaces and files: (The following files are in the doc/php/directory of the source package)
File list:
Copy Code code as follows:
cache.php
dasm.php
encoder.php
info.php
loader.php
session.php
shared_memory.php
Interface list:
Copy Code code as follows:
Array eaccelerator_cached_scripts ()
void Eaccelerator_cache_output (String $key, String $eval _code, [int $ttl = 0])
void Eaccelerator_cache_page (String $key, [int $ttl = 0])
void Eaccelerator_cache_result (String $key, string $code, [int $ttl = 0])
void Eaccelerator_caching (Boolean $flag)
void Eaccelerator_clean ()
void Eaccelerator_clear ()
Array eaccelerator_dasm_file (mixed $filename)
Mixed Eaccelerator_encode (mixed $src, [mixed $prefix = '], [string $pre _content = '], [string $post _content = '])
void eaccelerator_gc ()
Mixed Eaccelerator_get (String $key)
Array Eaccelerator_info ()
Array Eaccelerator_list_keys ()
void Eaccelerator_load ()
Boolean Eaccelerator_lock (String $key)
void Eaccelerator_optimizer (Boolean $flag)
void Eaccelerator_purge ()
Boolean eaccelerator_put (String $key, mixed $value, [int $ttl = 0])
Array eaccelerator_removed_scripts ()
Boolean eaccelerator_rm (String $key)
void Eaccelerator_rm_page (String $key)
Boolean eaccelerator_set_session_handlers ()
Boolean Eaccelerator_unlock (String $key)
Some of the following users translated the interface description:
Copy Code code as follows:
Eaccelerator_put ($key, $value, $ttl =0)
The $value is stored in the $key as a key to the cache (PHP4 support for the image type, look at the source as if Zend2 does not support), $ttl is the life cycle of this cache, the unit is seconds, omit this parameter or specify 0 for unlimited time until the server restart empty.
Eaccelerator_get ($key)
The return value is NULL if the cache has expired or does not exist, depending on $key the data that is stored in the corresponding eaccelerator_put () from the cache.
EACCELERATOR_RM ($key)
To remove a cache from $key
EACCELERATOR_GC ()
Remove clean all expired key
Eaccelerator_lock ($key)
A locking operation is added to the $key to ensure the synchronization of the data during multiple-process multithreaded operations. You need to call Eaccelerator_unlock ($key) to release the lock or wait for the end of the program request to automatically release the lock.
For example:
<?php
Eaccelerator_lock ("Count");
Eaccelerator_put ("Count", Eaccelerator_get ("Count") +1);
?>
Eaccelerator_unlock ($key)
Releasing locks according to $key
Eaccelerator_cache_output ($key, $eval _code, $ttl =0)
The output of the $eval _code code is cached $ttl seconds ($ttl parameter is the same as Eacclerator_put)
For example:
<?php eaccelerator_cache_output (' Test ', ' echo Time '); Phpinfo ();?>
Eaccelerator_cache_result ($key, $eval _code, $ttl =0)
The execution result of the $eval _code code is cached $ttl seconds ($ttl parameters are the same as Eacclerator_put), similar to the Cache_output
For example:
<?php eaccelerator_cache_result (' Test ', ' time ' (). "Hello"; "?>";
Eaccelerator_cache_page ($key, $ttl =0)
$ttl seconds to cache the current full-page page.
For example:
<?php
Eaccelerator_cache_page ($_server[' php_self '). " Get= '. Serialize ($_get), 30);
echo Time ();
Phpinfo ();
?>
Eaccelerator_rm_page ($key)
Deletes the cache executed by Eaccelerator_cache_page (), which is also the parameter $key
2, PHP code in the use of eaccelerator acceleration
In addition, the support for Eaccelerator has been integrated into the PHPCMS, and here is a section of code from PHPCMS
Copy Code code as follows:
Class Cache
{
function __construct ()
{
}
function Cache ()
{
$this->__construct ();
}
function Get ($name)
{
Return Eaccelerator_get ($name);
}
function set ($name, $value, $ttl = 0)
{
Eaccelerator_lock ($name);
Return Eaccelerator_put ($name, $value, $ttl);
}
function rm ($name)
{
Return Eaccelerator_rm ($name);
}
function Clear ()
{
return eaccelerator_gc ();
}
}