PHP Accelerator eaccelerator Configuration using the steps detailed

Source: Internet
Author: User
Tags echo date phpinfo vbulletin
This time to bring you PHP accelerator eaccelerator configuration using the steps in detail, the PHP accelerator eaccelerator configuration Use of the considerations are what, the following is the actual case, together to see.

In order to better improve the performance of the system to consider some optimization of PHP, the previous two years in contact with MMCache and eaccelerator, especially for eaccelerator very much, this optimization also chose it.

Share some eaccelerator configuration and optimization documents.

Directory:
I. Introduction of Eaccelerator
1. Background
2. Principle

Second, installation and configuration
1. Support Platform
2. System Requirements
3. Installation
4. php.ini file Configuration
5. Verify the installation

Iii. using eaccelerator to develop PHP code
1. API documentation and Interface description
2. Development examples

Iv. appendices and references
I, Eaccelerator introduction
1, background
Eaccelerator is a free, open-source PHP project for accelerated, optimized, compiled, and dynamic caching. It can improve the performance of PHP scripts by caching the compiled results of PHP code, making PHP script compilation problems that are always 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 by caching the compiled PHP code in shared memory, and when the user accesses the direct call to play the role of efficient acceleration. 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. The
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, it is not decompile like some other compilation tools, which makes the code safe 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: eaccelerator-0.9.5-beta.tar.bz2

#tar-zxvf./EACCELERATOR-0.9.5-BETA2.TAR.BZ2#CD eaccelerator-0.9.5-beta2#export php_prefix= "/usr/local" (Import the PHP installation directory into the environment variable, freebsd default is/usr/local) # $PHP _prefix/bin/phpize#./configure--enable-eaccelerator=shared-- with-php-config= $PHP _prefix/bin/php-config#make#make instal

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, verify 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 Tech Nologies
with Eaccelerator v0.9.5-beta2, Copyright (c) 2004-2006 eaccelerator, by Eaccelerator
I also have Zend installed on my machine Optimizer3.0.1, so see the following information:
This program makes use of the Zend Scripting Language engine:
Zend engine v2.1.0, Copyrigh T (c) 1998-2006 Zend Technologies
with Eaccelerator v0.9.5-beta2, Copyright (c) 2004-2006 eaccelerator, by Eaccelerato R
with Zend Extension Manager v1.0.10, Copyright (c) 2003-2006, by Zend Technologies
with Zend Optimizer v3.0.1, C Opyright (c) 1998-2006, by Zend Technologies
If you turn on the debug option for Eaccelerator, you can see a message similar to 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, complete 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  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_da  Sm_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 Eacce Lerator_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 EACC Elerator_removed_scripts () Boolean eaccelerator_rm (string $key) void Eaccelerator_rm_page (String $key) Boolean Eaccele Rator_set_session_handlers () BoOlean Eaccelerator_unlock (String $key) 

For more information on the above documentation, please refer to the official documentation: API documents
Here are some of the user interface after the translation of the description:
Eaccelerator_put ($key, $value, $ttl =0)
The $value to the $key as the key name in the cache (PHP4 support for the type of image, see the source is not supported in the Zend2), $ttl is the life cycle of this cache, the unit is the second, omit the parameter or specify 0 for unlimited, until the server restarts to empty.

Eaccelerator_get ($key) returns the  corresponding Eaccelerator_put () data from the cache according to the $key, if the cache has expired or does not exist then the return value is NULLEACCELERATOR_RM ($ Key)  $key Remove Cache eaccelerator_gc ()  Remove all expired Keyeaccelerator_lock ($key)  to $key plus lock operation, To ensure the synchronization of data during multi-process multithreading operations. You need to call Eaccelerator_unlock ($key) to release this lock or to automatically release this lock when the program request ends.
  <?php    Eaccelerator_lock ("Count");    Eaccelerator_put ("Count", Eaccelerator_get ("Count") +1));  ? >eaccelerator_unlock ($key)

Release the lock according to the $key

Eaccelerator_cache_output ($key, $eval _code, $ttl =0)

$eval the output cache of the _code code $ttl seconds ($ttl parameter same as Eacclerator_put)
For example:

<?php eaccelerator_cache_output (' Test ', ' echo Time ' (); phpinfo (); ', ');? >eaccelerator_cache_result ($key, $eval _code, $ttl =0)

Caches the execution results of the $eval _code code $ttl seconds ($ttl parameter with eacclerator_put), similar to Cache_output
For example:

  <?php eaccelerator_cache_result (' Test ', ' time () '. "Hello"; "," (?>);
Eaccelerator_cache_page ($key, $ttl =0)

Caches the current full page $ttl seconds.
For example:

  <?php    eaccelerator_cache_page ($_server[' php_self '). Get= '. Serialize ($_get), (+);    echo time ();    Phpinfo ();  ? >eaccelerator_rm_page ($key)

Deletes the cache executed by Eaccelerator_cache_page (), and the parameters are also $key

2. Use eaccelerator acceleration in PHP code
Test eaccelerator Powerful Power: (This code may not work in CLI mode)

<?phpclass Test_cache {  var $pro = ' Hello ';  function Test_cache () {    echo "Object created!<br>\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!<br>\n";} else {  echo "cached<br>\n";} Echo $tt->pro; $tt->func (); $tt->now (Time () + 86400);? >

In addition, it is said that the support for Eaccelerator has been integrated in the famous vbulletin 3.60Beta version.
A piece of code from vbulletin inside

##############//eaccelerator/** * Class for fetching and initializing the VBulletin datastore from Eaccelerator * * @ Package VBulletin * @version $Revision: 0.1 $ * @date $Date: 2005/06/12 13:14:18 $ */class Vb_datastore_eaccelerator Exte NDS Vb_datastore {/** * Fetches the contents of the Datastore from Eaccelerator * * @param array array of items to fetch From the datastore * * @return void */function Fetch ($itemarray) {if (!function_exists (' Eaccelerator_get ')) {Trigger_er Ror ("Eaccelerator not Installed", e_user_error); }foreach ($this->defaultitems as $item) {$this->do_fetch ($item);} if (Is_array ($itemarray)) {foreach ($itemarray as $item) {$this->do_fetch ($item);}} $this->check_options ();//Set the version number variable $this->registry->versionnumber =& $this registry->options[' templateversion ']; }/** * Fetches the data from shared memory and detects errors * * @param string title of the datastore item * * @return VO ID */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 Buil D ($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); } }

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

PHP7 using LIB library case code analysis based on function mode

PHP to find the link in the list of the Ring entry node detailed steps

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.