PHP accelerated eaccelerator Configuration and usage Guidelines _php tips

Source: Internet
Author: User
Tags bz2 eval php script phpinfo hosting vps vbulletin zend
Some time ago completed the server from FreeBSD4.10 to 6.1 upgrade, while the PHP also upgraded to the latest Php5.1.4,apache also upgraded to the latest Apache2.2, in order to better improve the performance of the system to consider some of the PHP optimization, the previous two years contacted MMCache and EAC Celerator, especially to eaccelerator very much like, this optimization also chose it, following the collation of a number of documents and share.

Directory:
First, Eaccelerator Introduction
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
Third, the use of eaccelerator development of PHP code
1, API documentation and interface description
2. Development example
Iv. Appendices and reference materials

First, Eaccelerator Introduction

1. Background
Eaccelerator is a free and 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 the PHP script compilation problem that has always been complicated and far from us completely solved. By using Eaccelerator, you can optimize your PHP code execution speed, reduce server load, can increase PHP application execution speed up to 10 times times.

The Eaccelerator project was born in 2004 when it was proposed and put into development as a branch of the Turck MMCache project. Turck MMCache, developed by the stogov, is a very good PHP memory cache acceleration System, there are still a large number of eaccelerator code applied to the project, currently 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 into shared memory and calling it directly when the user accesses it, which can play an efficient role in accelerating. It's very efficient, from creating shared memory to finding compiled code in a very short time, and for files and code that can't be cached in shared memory, Eaccelerator can also cache them on the system disk.

Eaccelerator also support the compilation and interpretation of PHP code execution, you can use the encoder.php script to compile the PHP code to protect the code, the compiled code must run in the installation of the Eaccelerator environment. Eaccelerator compiled code can not be decompile, it is not like some other compiler tools to decompile, which makes the code more secure and efficient.

Second, eaccelerator installation configuration

1. Support Platform
Since Aaccelerator provides most of the shared-memory API, it will be better supported on *nix platforms, although the binary version based on Windows platform has been released, but I am here to provide only the *nix platform based configuration and instructions. Currently available 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 code 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 PHP installation directory into 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 Install

4. ini file configuration
The installation is complete, the php.ini file is configured below, and Eaccelerator provides two configurations and invocation methods, respectively.

Install as Zend extension mode:

zend_extension= "/usr/local/lib/php/20050922/eaccelerator.so"
Eaccelerator.shm_size= "16"
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 have PHP installed in thread safe mode, you must replace the first line of "Zend_extension" with "Zend_extension_ts".

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

extension= "Eaccelerator.so"
Eaccelerator.shm_size= "16"
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 on the php.ini file, refer to the Readme documentation for the source directory or visit the Official document:INI setting

After completing the installation configuration, we will finally create the cache directory

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

5, verify the installation results
Access your Phpinfo () page through your browser or run Php-i get PHP configuration information, which means that the installation is successful if you see a message like the following.

This program makes the Zend scripting Language Engine:
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
With Eaccelerator V0.9.5-beta2, the Copyright (c) 2004-2006 eaccelerator, by Eaccelerator

I also have Zend Optimizer3.0.1 installed on my machine, so I see the following information:

This program makes the Zend scripting Language Engine:
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
With Eaccelerator V0.9.5-beta2, the Copyright (c) 2004-2006 eaccelerator, by Eaccelerator
With Zend Extension Manager v1.0.10, Copyright (c) 2003-2006, by Zend Technologies
With Zend Optimizer v3.0.1, Copyright (c) 1998-2006, by Zend Technologies

If you turn on the eaccelerator debug option, you can see information similar to the following from the log

#tail/var/log/httpd/eaccelerator_log
Eaccelerator hit: "/var/www/toplee.com/blog/index.php"
Eaccelerator hit: "/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, and 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, convenient and stable way to implement native caching, because most code implementations are based on shared memory, so they can only be used on the *nix platform, and Windows platform Michael is temporarily unaware of the time when this is supported.
Eaccelerator provides the following API interfaces and files: (The following files are in the doc/php/directory of the source 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 on the above documentation please refer to official documentation:API Documents

Some of the following users translated the interface description:

Eaccelerator_put ($key, $value, $ttl =0)
The $value is stored in the $key as a key to the cache (PHP4 support for the image type, look at the source as if Zend2 does not support), $ttl is the life cycle of this cache, the unit is seconds, omit this parameter or specify 0 for unlimited time until the server restart empty.

Eaccelerator_get ($key)
The return value is NULL if the cache has expired or does not exist, depending on $key the data that is stored in the corresponding eaccelerator_put () from the cache.

EACCELERATOR_RM ($key)
To remove a cache from $key

EACCELERATOR_GC ()
Remove clean all expired key

Eaccelerator_lock ($key)
A locking operation is added to the $key to ensure the synchronization of the data during multiple-process multithreaded operations. You need to call Eaccelerator_unlock ($key) to release the lock or wait for the end of the program request to automatically release the lock.
For example:
<?php
Eaccelerator_lock("Count");
Eaccelerator_put("Count",Eaccelerator_get("Count")+1));
?>

Eaccelerator_unlock ($key)
Releasing locks according to $key

Eaccelerator_cache_output ($key, $eval _code, $ttl =0)
The output of the $eval _code code is cached $ttl seconds ($ttl parameter is the same as Eacclerator_put)
For example:
<?php Eaccelerator_cache_output('Test','echo Time (); Phpinfo ();',30);?>

Eaccelerator_cache_result ($key, $eval _code, $ttl =0)
The execution result of the $eval _code code is cached $ttl seconds ($ttl parameters are the same as Eacclerator_put), similar to the Cache_output
For example:
<?php Eaccelerator_cache_result('Test ' , ' time (). "Hello"; ' , ) ; ?

Eaccelerator_cache_page ($key, $ttl =0)
  Cache 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)
  Delete cache executed by   Eaccelerator_cache_page (). parameter is also $key

2, PHP code in the use of eaccelerator acceleration

Here's a test code that you can test for eaccelerator powerful power: (This code may not work in CLI mode)

<?php
Class 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 in the famous vbulletin 3.60Beta version has been integrated with the support of Eaccelerator, the following is a section from the vbulletin inside the code

Copy Code code as follows:

// #############################################################################
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 extends 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_error ("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 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 reference materials
Eaccelerator Official website: http://eaccelerator.net
Websites using Eaccelerator?

http://www.advfn.com/(2006/03/03) Advanced Financial Network, serves over 7 million page hits/day.
http://www.domaincity.co.uk/(2005/01/29) Andrew hutchings-linux guru-just A quick message to say we are the now using EAC Celerator as a replacement for MMCache on 2 of my 3 node round robin clusters, 2.5million hits per day. We'll be doubling this in the next few week, as as the implementing new clusters.
http://www.ets-online.de/(2005/02/07) Denny Reeh-system developer-the e/t/s Didactic Media provides an elearning serv ER (Distance Learning System) written in PHP. We are hosting the systems for our customers mainly by ourself. So we have 5 live-servers (FreeBSD, Apache2, PhP4, eaccelerator) with 5.5 million hits/per month. Without eaccelerator we should have installed more servers for good performance and secondly we improve the customer Convenience by quartering the medium response time of a script.
http://www.gorgoyle.com/(2005/08/03) gorgoyle.com is yet Another Debian Personal servers with just a few lost Internet Wan Derers passing by, powered through a glorious Celeron 433 that needed some air ... With Eaccelerator the quite impressive:users say the server speed was now 10000% higher (no joke!) So thank your all and keep up the good work!!! Server:eaccelerator 0.9.5 Beta 1 apache/2.0.55 (Debian) mod_python/3.1.3 python/2.3.5 php/4.4.2-1 mod_ssl/2.0.55 OpenSSL /0.9.8a mod_perl/2.0.2
http://www.mafia-inc.de/(2005/05/24) The mafia-incorporated is a succesfull Browser game with around 2.500.000 page Impre Ssions and over 5000 users. server:php Version 4.3.10-9, Eaccelerator 0.9.2a, Debian, Apache 2.0.53
http://www.mondespersistants.com/(2005/01/07) An, game oriented French website with 6 Pageloads monthly. Http://guildes.mondespersistants.com is a full PHP5 oo development. Theses websites are running under Freebsd/apache 1.3/php 5.0.3/eaccelerator 0.9.2
http://www.moviemaze.de/(2005/12/09) Markus Ostertag-movie Maze is a large German online-magazine with trailer, WALLPAP Er, reviews, news and much more. Currently we use three servers (Suse & Debian with Apache 2, PHP4) with Eaccelerator and provide more than 3TB data to ~ Mio. Users each month.
Http://www.rtvslo.si (2005/01/04) The Slovenian national RTV Station and its News/misc portal with forums. Over 3500 users and more than 37000 forum messages in a year. Two round-robin servers for the masses, and a administrator server. 6 Pageloads Monthly.
http://www.shroomery.org/(2006/03/28) A site about mushrooms and mycology, serving 20,000,000 pages per month. Web and database server are identical dual 64-bit xeons with 4GB and SCSI RAID5 running. Eaccelerator help keep We page generation time under. 1 second!

http://www.sourceforge.net/(2005/04/25) SourceForge.net is the world ' s largest Open Source software development Web site Hosting more than 100,000 projects and over 1,000,000 registered users with a centralized for resource managing, Issues, communications, and code. SourceForge.net has the largest repository of Open Source code and applications on the Internet, and hosts more Open Source Development products than any other site or network worldwide. SourceForge.net provides a wide variety of services to projects we host, and to the Open Source community. Eaccelerator is used on the webserver cluster for their frontpage.
Companies offering hosting with Eaccelerator enabled?

http://lylix.net/(2006/04/29) offering webhosting w/apache/2.0.55, PHP 5.0.5, and Eaccelerator 0.9.5 on Beta1 Lin UX servers. Also a provider of quality Virtual Private Server (VPS) hosting, including and 64-bit platforms. Most VPS images have a pre-installed LAMP environment W/eaccelerator installed and configured.
http://www.ulyssis.org A Student organisation which provides shell and Internet services for students at very cheap prices .

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.