Discuss the API development details of PHP using eAccelerator. 1. API and documentation description: eAccelerator provides a convenient and stable local cache implementation method. because most code implementations are based on shared memory, they can only be used on the * nix platform.
1. API and documentation description:
EAccelerator provides a convenient and stable local cache implementation method. because most code implementations are based on shared memory, they can only be used on the * nix platform, on Windows, Michael does not know when this support will be available.
EAccelerator provides the following API interfaces and files: (the following files are in the doc/php/directory of the source code package)
File list:
The code is as follows:
Cache. php
Dasm. php
Encoder. php
Info. php
Loader. php
Session. php
Shared_memory.php
Interface list:
The code is 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 translated interfaces are described below:
The code is as follows:
Eaccelerator_put ($ key, $ value, $ ttl = 0)
Save $ value to the cache with $ key as the key name (the object type is supported in php4, and the source code does not seem to be supported in zend2). $ ttl is the cache lifecycle, the unit is seconds. If this parameter is omitted or 0 is specified, the operation is not limited until the server is restarted and cleared.
Eaccelerator_get ($ key)
According to $ key, the corresponding eaccelerator_put () stored data is returned from the cache. if the cache has expired or does not exist, the return value is NULL.
Eaccelerator_rm ($ key)
Remove cache based on $ key
Eaccelerator_gc ()
Remove all expired keys
Eaccelerator_lock ($ key)
Add a lock operation to $ key to ensure data synchronization during multi-process and multi-thread operations. You need to call eaccelerator_unlock ($ key) to release the lock or wait until the end of the program request to automatically release the lock.
For example:
Eaccelerator_lock ("count ");
Eaccelerator_put ("count", eaccelerator_get ("count") + 1 ));
?>
Eaccelerator_unlock ($ key)
Release lock based on $ key
Eaccelerator_cache_output ($ key, $ eval_code, $ ttl = 0)
Cache the $ eval_code output for $ ttl seconds (the $ ttl parameter is the same as eacclerator_put parameter)
For example:
Eaccelerator_cache_result ($ key, $ eval_code, $ ttl = 0)
Cache the execution result of $ 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 entire page for $ ttl seconds.
For example:
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 (). the parameter is also $ key.
2. use eAccelerator to accelerate PHP code
In addition, the eAccelerator support has been integrated in PHPCMS. The following is a piece of code from PHPCMS.
The code is 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 ();
}
}
EAccelerator provides a convenient and stable local cache implementation method. because most code implementations are based on shared memory, they can only be used on * nix platforms...