EAccelerator is an excellent PHP accelerator. By caching compiled PHP code files, the PHP compilation overhead on the server is almost zero. The overhead of the eAccelerator is also very small. The latest PHP5.4.8 installation of eAccelerator requires the installation of a higher version, which means the compilation is not over. Official Website: eaccelerat
EAccelerator is an excellent PHP accelerator. By caching compiled PHP code files, the PHP compilation overhead on the server is almost zero. The overhead of the eAccelerator is also very small. The latest PHP5.4.8 installation of eAccelerator requires the installation of a higher version, which means the compilation is not over. Official website: http: // eaccelerat
EAccelerator is an excellent PHP accelerator. By caching compiled PHP code files, the PHP compilation overhead on the server is almost zero. The cost of the eAccelerator is also very small.
Install eAccelerator in PHP5.4.8,
It should be noted that the high version should be installed, and the compilation cannot be completed after the low version.
Official Website: http://eaccelerator.net/
1. Download and install eAccelerator
# Wget https://github.com/eaccelerator/eaccelerator/tarball/master
The latest signature is eaccelerator-42067ac.tar.gz.
# Tar zxvf eaccelerator-42067ac.tar.gz
You need to install php extension phpize, if you do not understand phpize can see this: http://blog.csdn.net/21aspnet/article/details/8193482
Note that you need to write the php-config file under phpize corresponding to the php installation path.
#/Usr/local/webserver/php/bin/phpize
You need to remember the generated prompt information.
/Usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-
20100525/
#./Configure -- enable-eaccelerator = shared -- with-php-config =/usr/local/webserver/php/bin/php-config
# Make
It should be noted that the high version should be installed, and the compilation cannot be completed after the low version.
# Make install
2. Configure the php. ini configuration file
[Eaccelerator]
Extension = "/data/webserver/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator. so"
Eaccelerator. shm_size = "32"
Eaccelerator. cache_dir = "/data/cache/eaccelerator"
Eaccelerator. enable = "1"
Eaccelerator. optimizer = "1" (if optimizer is not installed, set it to 0 to disable the Acceleration Engine. Otherwise, a PHP script error occurs)
Eaccelerator. check_mtime = "1"
Eaccelerator. debug = "0"
Eaccelerator. filter = ""
Eaccelerator. shm_max = "0"
Eaccelerator. shm_ttl = "0"
Eaccelerator. shm_prune_period = "0"
Eaccelerator. shm_only = "0"
Eaccelerator. compress = "1"
Eaccelerator. compress_level = "9"
Create cache directory:
# Mkdir-p/data/cache/eaccelerator
# Chmod 0777/data/cache/eaccelerator
Restart Apache:
# Service httpd restart
3. Check whether ZendOptimizer and eaccelerator have been installed successfully.
Create a phpinfo. php file with the following content:
Phpinfo ();
?>
Place the file in the website directory and access it in the browser. If the following content appears, the installation is successful:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
With eAccelerator v0.9.5, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
With Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by Zend Technologies
With Zend Optimizer v3.2.2, Copyright (c) 1998-2006, by Zend Technologies
Ii. Detailed description of eaccelerator configuration (translated according to official English instructions)
Extension = "/data/webserver/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator. so"
Explanation: PHP extension eaccelerator. so path.
--------------------
Eaccelerator. shm_size = "32"
Explanation: the shared memory size (in MB) That eaccelerator can use ).
In Linux, the maximum memory usage of a single process is limited by the number (in bytes) set in/proc/sys/kernel/shmmax ), for example, the shmmax of CentOS 4.4 defaults to 33554432 bytes (33554432 bytes/1024/1024 = 32 MB ).
Temporarily change this value:
# Echo bytes>/proc/sys/kernel/shmmax
The value is automatically restored every time the system is restarted. If you want to change it permanently, you can modify the/etc/sysctl. conf file and set it:
Kernel. shmmax = number of bytes
--------------------
Eaccelerator. cache_dir = "/data/cache/eaccelerator"
Explanation: cache path. You can run the command mkdir-p/data/cache/eaccelerator to create the directory, and then run the command chmod 0777/data/cache/eaccelerator to set the directory permission to 0777.
--------------------
Eaccelerator. enable = "1"
Explanation: enable or disable the eaccelerator. "1" means to open, "0" means to close. The default value is "1 ".
--------------------
Eaccelerator. optimizer = "1" (if optimizer is not installed, set it to 0 to disable the Acceleration Engine. Otherwise, a PHP script error occurs)
Explanation: enabling or disabling code optimization can speed up code execution. "1" means to open, "0" means to close. The default value is "1 ".
--------------------
Eaccelerator. check_mtime = "1"
Explanation: When this option is enabled, the eaccelerator checks the PHP file modification time for each request to see if it has been modified. This takes a little time. If the PHP file has been modified, the eaccelerator recompiles and caches the PHP file. When this option is disabled, if the PHP file is modified, you must manually delete the eaccelerator cache to display the modified PHP file. "1" means to open, "0" means to close. The default value is "1 ".
--------------------
Eaccelerator. debug = "0"
Explanation: enable or disable debugging records. When enabled, the eaccelerator writes every request to a cached file into the log. Enabling this option is only helpful for debugging whether the eaccelerator has a BUG. "1" means to open, "0" means to close. The default value is "0 ".
--------------------
Eaccelerator. filter = ""
Explanation: determines which PHP files should be cached. You can specify a range (for example, "*. php *. phtml") to cache the specified file. If the range is! The specified file will not be cached. The default value is "", indicating that all PHP files are cached.
--------------------
Eaccelerator. shm_max = "0"
Explanation: a user can use functions such as eaccelerator_put to load the maximum data in the shared memory. The default value is "0", indicating no restriction. (In bytes)
--------------------
Eaccelerator. shm_ttl = "0"
Explanation: when there is not enough free shared memory to try to buffer a new script, files that have not been accessed before shm_ttl seconds will be deleted. The default value is "0", indicating that no old scripts are deleted from the shared memory. (Unit: seconds)
--------------------
Eaccelerator. shm_prune_period = "0"
Explanation: when there is not enough free shared memory to buffer a new script, all old scripts will be deleted, provided that the attempt was executed before shm_prune_period seconds. The default value is "0", indicating that no old scripts are deleted from the shared memory. (Unit: seconds)
--------------------
Eaccelerator. shm_only = "0"
Explanation: enable or disable caching compiled scripts on the disk. This parameter has no effect on session data and content cache. The default value is "0", indicating that disk and shared memory are used for caching.
--------------------
Eaccelerator. compress = "1"
Explanation: enable or disable cache content compression. "1" means to open, "0" means to close. The default value is "1 ".
--------------------
Eaccelerator. compress_level = "9"
Explanation: Memory compression level. The default value is 9, indicating maximum compression.
# This is the so location of my machine.
Extension = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator. so"
# Set the cache size.
Eaccelerator. shm_size = "64"
# Cache directory
The actual configuration of eaccelerator. cache_dir = "/usr/local/webserver/eaccelerator_cache" is not recommended in the WEB directory. We recommend that you put it outside the web directory for security reasons.
# The website directory, which controls the unlocked eAccelerator source code package. copy the php file to a directory on your WEB server so that other files can be accessed through http. If no cached page list is displayed, you can still see the memory information.
Eaccelerator. allowed_admin_path =/usr/www/
Eaccelerator. enable = "1"
Eaccelerator. optimizer = "1" (if optimizer is not installed, set it to 0 to disable the Acceleration Engine. Otherwise, a PHP script error occurs)
Eaccelerator. check_mtime = "1"
Eaccelerator. debug = "0"
Eaccelerator. filter = ""
Eaccelerator. shm_max = "0"
Eaccelerator. shm_ttl = "0"
Eaccelerator. shm_prune_period = "0"
Eaccelerator. shm_only = "0"
Eaccelerator. compress = "1"
Eaccelerator. compress_level = "9"
Eaccelerator. keys = "disk_only"
Eaccelerator. sessions = "disk_only"
Eaccelerator. content = "disk_only"
Set the location where the content cache is stored. You can set it:
Shm_and_disk in shared cache and hard disk (default)
Shm has shared memory by default. If the shared memory is full or the size exceeds the value of "eaccelerator. shm_max", it is saved to the hard disk.
Shm_only is stored only in the shared memory.
Disk_only is stored on the hard disk
None
In order to check the effect, set the disk to exist.
Add Permissions
# Mkdir/usr/local/webserver/eaccelerator_cache
# Chmod 777/usr/local/webserver/eaccelerator_cache
3. Test and view phpinfo ()
4. View cache folders
Graphic Interface
This indicates that the cache is successfully generated.
5. Better monitoring methods
The address of the eAccelerator control panel. The installation package contains a control. PHP file, copy it to any directory of the website, you can use it to view and manage, this must be specified, otherwise there will be errors when viewing the cache content, access the default user name is: admin, password: eAccelerator
Note: The detailed information will be displayed when this configuration is added to the previous php. ini configuration file.
Eaccelerator. allowed_admin_path =/usr/www/
Restart apache to clear the cache
Documentation:
Eaccelerator. shm_size = "8"
The amount of shared memory that eAccelerator can use (in MB ). "0" refers to the default value of the operating system. The default value is "0". It can be adjusted according to the actual situation of the server: 16, 32, 64, 128.
Eaccelerator. cache_dir = "/usr/local/webserver/eaccelerator_cache"
This directory is used for disk cache, where eAccelerator stores pre-compiled code, process data, content, and user-defined content. The same data can also be stored in the shared memory (this can increase the access speed)
Eaccelerator. enable = "1"
Enable or disable eAccelerator. "1" is enabled, and "0" is disabled. The default value is "1 ".
Eaccelerator. optimizer = "1" (if optimizer is not installed, set it to 0 to disable the Acceleration Engine. Otherwise, a PHP script error occurs)
Enable or disable the internal optimizer to speed up code execution. "1" is enabled, and "0" is disabled. The default value is "1 ".
Eaccelerator. check_mtime = "1"
Open or close the PHP file modification check. "1" indicates opening, and "0" indicates closing. The default value is "1 ".
Eaccelerator. debug = "0"
Enable or disable debugging logging. "1" is enabled, and "0" is disabled. The default value is "0 ". Logs will be written to the cache hit records.
Eaccelerator. filter = ""
Determine which PHP files must be cached. You can specify the cached and non-cached file types (for example, "*. php *. phtml "! ", Files matching these parameters are ignored. The default value is "", that is, all PHP files will be cached.
Eaccelerator. shm_max = "0"
When the "eaccelerator_put ()" function is used, it is prohibited to store excessive files in the shared memory. This parameter specifies the maximum value that can be stored, in bytes (10240, 10 K, 1 M ). "0" is unlimited. The default value is "0 ".
Eaccelerator. shm_ttl = "3600"
When the eAccelerator fails to obtain the shared memory size of the new script, it will delete all script caches that have not been accessed in the last "shm_ttl" seconds from the shared memory. The default value is "0", indicating that no cached files are deleted from the shared memory.
Eaccelerator. shm_prune_period = "3600"
When the eAccelerator fails to get the shared memory size of the new script, it will try to delete the cache script earlier than "shm_prune_period" from the shared memory. The default value is "0", indicating that no cached files are deleted from the shared memory.
Eaccelerator. shm_only = "0"
Allow or disable caching compiled scripts on disks. This option is invalid for session data and content caching. The default value is "0", indicating that the disk and shared memory are used for caching.
Eaccelerator. compress = "1"
Allows or disables content caching. The default value is "1", which allows compression.
Eaccelerator. compress_level = "9"
Specifies the compression level of the content cache. The default value is 9, which is the highest level.
Eaccelerator. keys = "disk_only"
Eaccelerator. sessions = "disk_only"
Eaccelerator. content = "disk_only"
Set the location where the content cache is stored. You can set it:
Shm_and_disk in shared cache and hard disk (default)
Shm has shared memory by default. If the shared memory is full or the size exceeds the value of "eaccelerator. shm_max", it is saved to the hard disk.
Shm_only is stored only in the shared memory.
Disk_only is stored on the hard disk
None
6. test performance
Quick Sort code
[Php]View plaincopyprint?
-
- Function quickSort ($ arr)
- {
- $ Len = count ($ arr );
- If ($ len <= 1 ){
- Return $ arr;
- }
- $ Key = $ arr [0];
- $ Left_arr = array ();
- $ Right_arr = array ();
-
- For ($ I = 1; $ I <$ len; $ I ++ ){
- If ($ arr [$ I] <= $ key ){
- $ Left_arr [] = $ arr [$ I];
- } Else {
- $ Right_arr [] = $ arr [$ I];
- }
- }
-
- $ Left_arr = quickSort ($ left_arr );
- $ Right_arr = quickSort ($ right_arr );
- Return array_merge ($ left_arr, array ($ key), $ right_arr );
- }
-
-
- $ Arr = array (6, 3, 8, 5, 9, 2, 10 );
- Echo'
';
- Print_r (quickSort ($ arr ));
- ?>
'; print_r(quickSort($arr)); ?>
Test Method
# AB-n 1000 http: // 192.168.2.107/quicksort. php
Consecutive tests, the main performance indicator is Requests per second
Not used on the leftEAcceleratorThe right side is used.
For 10 consecutive tests, the basic data is still relatively stable.
UsedEAcceleratorTime is better than not used!
Use strace to view php source code in C Language
You can see how the eAccelerator cache is read.
Additional reading:
EAccelerator provides the following API interfaces and files: (the following files are in the doc/php/directory of the source code package)
File List:
Cache. php
Dasm. php
Encoder. php
Info. php
Loader. php
Session. php
Shared_memory.php
Interface list:
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)
For more information, see the official documentation.
Some translated interfaces are described below:
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.
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(); }}