Purpose of using eAccelerator to accelerate PHP code
Source: Internet
Author: User
Use eAccelerator to accelerate PHP code
EAccelerator is really a good thing (its predecessor is truck-mmcache ).
Simply put, it is a cache system that works with PHP (supporting PHP5) and exchanges data through shared memory or disk files.
It is widely used in PHP source code "encoding" (hereinafter referred to as "encryption") and cache the intermediate code executed by PHP to accelerate. There have been a lot of articles on eA installation and use, and they are also very detailed. this time I would like to recommend using it to assist program design caching. It provides a set of APIs as follows:
It is a very convenient and stable local cache implementation method. Currently, this part of the design only supports shared memory, so it can only be used for Unix-Like OS, windows is no better off.
1. 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.
2. 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.
3. eaccelerator_rm ($ key)
Remove cache based on $ key
4. eaccelerator_gc ()
Remove all expired keys
5. 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 ));
?>
6. eaccelerator_unlock ($ key)
Release lock based on $ key
7. 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:
8. 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:
9. 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 ();
?>
10. eaccelerator_rm_page ($ key)
Deletes the cache executed by eaccelerator_cache_page (). the parameter is also $ key.
______________________________________________
(For a simple example, check its power. Note that it may not work in cli mode !)
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 );
?>
The following are comments from netizens:
--------------------------------------------------------------------------------
Showsa replied to: 2005-12-31 19: 51: 56win! Http://www.arnot.info/eaccelerator/
A small bug in the latest version of eAccelerator 0.9.4-rc1 was reported by a large number of [warn] (32) Broken pipe: write pipe_of_death error message solution: modify debug. c file ---------------------------------------------/*** Close the debug system. */void ea_debug_shutdown () {fflush (F_fp); // The source statement does not detect the file handle when the file is closed. // fclose (F_fp); // change it to if (F_fp! = Stderr) fclose (F_fp); F_fp = NULL ;}
Soichiro replied to: 2006-01-10 22: 01: 21 eAccelerator/truck-mmcache. I have two high-load systems, one based on Drupal and the other based on PostNuke, after eAccelerator is used, Drual speed is increased by 100 times, PostNuke is increased by 10 times, and PostNuke is improved by less because it is fast.
Wangyih replied to: 10:48:11 and how is the squid ratio?
Showsa replied to the following question: how can we compare it with squid at 23:23:44,? squid is a cache page running result. if it is not displayed in real time, squid is definitely better, but it cannot be used in forums and so on, using eaccelerator/memcache can greatly improve efficiency
Yarco replied to: 10:00:43, but it is said that there is a conflict with the encode code... I don't know how the current compatibility with zend is?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.