PHP accelerator eaccelerator equipped and used guide

Source: Internet
Author: User
Tags echo date vbulletin
PHP Accelerator eaccelerator Configuration and Usage guide

I. Introduction of Eaccelerator

1. Background
Eaccelerator is a free, open source PHP accelerated, optimized, compiled, and dynamically cached project that can improve the performance of PHP scripts by caching the compiled results of PHP code, making PHP scripting problems that have always been complex and far from us completely resolved. By using Eaccelerator, you can optimize your PHP code execution speed, reduce server load, and increase your PHP application execution speed up to 10 times times.

The Eaccelerator project was born in 2004, when it was presented and developed as a branch of the Turck MMCache project. Turck MMCache was developed by Dmitry Stogov, is a very good PHP memory cache acceleration System, still have a lot of eaccelerator code to apply to the project, the project has not been updated for a long time, Support for the latest php5.x is not yet available.

2. Principle
Eaccelerator efficiently accelerates by caching compiled PHP code in shared memory and invoking it directly when the user accesses it. It is very efficient, from creating shared memory to finding compiled code that is done in a very short time, and for files and code that cannot be cached in shared memory, Eaccelerator can also cache them on the system disk.

Eaccelerator also supports the compilation and interpretation of PHP code, you can compile the PHP code by encoder.php script to achieve the purpose of protecting the code, after the compiled code must be run in the installation of Eaccelerator environment. Eaccelerator compiled code cannot be deserialized, and it is not decompile like some other compilation tools, which makes the code more secure and efficient.

Second, eaccelerator installation configuration

1. Support Platform
Since Aaccelerator provides most of the shared memory-based APIs, it will be better supported on *nix platforms, although binary versions of Windows-based platforms are also released, but here I only provide configuration and instructions based on the *nix platform. Currently supported platforms include Linux, FreeBSD, OpenBSD, Mac OS X, Solaris, AIX en-UX.

2. System Requirements
PhP4 or PHP5
Autoconf
Automake
Libtool
M4
Eaccelerator only supports PHP installed using mod_php or fastcgi mode

?

3. Installation
First go to eaccelerator official download the latest version of the source package: http://sourceforge.net/projects/eaccelerator/

?

4. ini file configuration
The installation is complete, the following begins to configure the php.ini file, and Eaccelerator provides two configuration and invocation methods, respectively, as follows.

Install as Zend extension mode:

zend_extension= "/usr/local/lib/php/20050922/eaccelerator.so" eaccelerator.shm_size= "eaccelerator.cache_dir=" /tmp/eaccelerator "eaccelerator.enable=" 1 "eaccelerator.optimizer=" 1 "eaccelerator.check_mtime=" 1 " eaccelerator.debug= "0" eaccelerator.log_file = "/var/log/httpd/eaccelerator_log" 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"

?

If you use the thread safe mode installed PHP, you must use "zend_extension_ts" to replace the first line of "Zend_extension".

Install as PHP extension mode: (This is the way most of them are used)

?

extension= "eaccelerator.so" eaccelerator.shm_size= "eaccelerator.cache_dir="/tmp/eaccelerator " eaccelerator.enable= "1" eaccelerator.optimizer= "1" eaccelerator.check_mtime= "1" eaccelerator.debug= "0" Eaccelerator.log_file = "/var/log/httpd/eaccelerator_log" 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"

?

For detailed configuration instructions for the php.ini file, please refer to the Readme document of the source directory or access the official documentation: INI setting

After the installation configuration is complete, we will finally create the cache directory

?

#mkdir/tmp/eaccelerator#chmod 777/tmp/eaccelerator

5. Verifying the installation results
Access your Phpinfo () page through a browser or run php-i to get PHP configuration information, if you see a message 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

?

If you turn on the debug option for Eaccelerator, you can see information like the following in the log

#tail/var/log/httpd/eaccelerator_logeaccelerator Hit: "/var/www/toplee.com/blog/index.php" EAccelerator Hits: "/var/ Www/toplee.com/blog/wp-blog-header.php "Eaccelerator hit:"/var/www/toplee.com/blog/wp-config.php "EACCELERATOR hit : "/var/www/toplee.com/blog/wp-settings.php" Eaccelerator hit: "/var/www/toplee.com/blog/wp-content/plugins/ Wp-cache/wp-cache-phase1.php "...

?

The above information indicates that the files have been cached and hit.

At this point, we have completed all the installation and configuration, enjoy the eaccelerator to your surprise, according to Michael's Test, the effect is indeed quite good.

?

Third, in PHP can use the Eaccelerator API development

1. API and Documentation Description:

Eaccelerator provides a convenient and stable native cache implementation, because most code implementations are based on shared memory and can only be used in the *nix platform, and the Windows platform Michael does not know when this is supported.
Eaccelerator provides the following API interface and files: (The following files are in the source package doc/php/directory)

File list:

?

cache.phpdasm.phpencoder.phpinfo.phploader.phpsession.phpshared_memory.php

?

Interface list:

Array eaccelerator_cached_scripts () void Eaccelerator_cache_output (String $key, String $eval _code, [int $ttl = 0]) void ea Ccelerator_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 = '], [Strin G $post _content = "]) void eaccelerator_gc () mixed Eaccelerator_get (string $key) array eaccelerator_info () array Eaccele Rator_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_re Moved_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 on the above documentation, please refer to the official documentation: API documents

?

2. Use eaccelerator acceleration in PHP code

Here's a test code, you can test the power of Eaccelerator: (the code may not work in CLI mode)

?

 
  \ 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 tes T_cache;  Eaccelerator_put ("Test_tt", $tt);  echo "No cached!
\ n ";} else { echo "cached
\ n ";} echo $tt->pro; $tt->func (); $tt->now (Time () + 86400);? >

?

In addition, it is said that in the famous vbulletin 3.60Beta version of the integration of Eaccelerator support, the following is a piece of code from the vbulletin inside

 Defaultitems as $item) {$this->do_fetch ($item); } if (Is_array ($itemarray)) {foreach ($itemarray as $item) {$this-&G            T;do_fetch ($item);         }} $this->check_options (); Set the version number variable $this->registry->versionnumber =& $this->registry->options[' Temp    Lateversion '];  }/** * Fetches the data from the 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); }}?>

?

Iv. Appendices and references
Eaccelerator Official website: http://eaccelerator.net

?

  • Related Article

    Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.