PHP加速器eAccelerator文档翻译 (PHP心得)
发布于 2007-11-06 11:02 1 阅读:62,315 评论:1 标签: eAccelerator Linux PHP 翻译 文档

  前端时间用到这个,看了一下英文文档觉得还是看最原始的资料看到的东西最全。比如说eAccelerator自带了共享内存管理的程序,这个在我找到的中文资料里面就没有看到过。

  本文翻译的是:Release-0.9.5.2 ,官网是:http://www.eaccelerator.net/。原文附后,英文水平不高,如果您发现有不对的地方,还请告诉我!

--------------------------

PHP的eAccelerator
=====================

什么是eAccelerator?
----------------------
eAccelerator是一个的免费、开源的PHP模块,它能够为提供PHP加速、优化、加码、和动态内容缓存功能。它通过存储PH脚本编译后的状态而加快执行PHP脚本的速度,而不需要频繁的编译这个PHP脚本。而且它能优化PHP脚本,以提高执行PHP的速度。eAccelerator特色是减少了服务器负载、使PHP脚本加速1-10倍。

eAccelerator是TurckMMCache的一个分支
(请详见Dmitry Stogov维护的:http://sourceforge.net/project/turckmm-cache/

eAccelerator把编译好的PHP程序存储在共享内存里面,并直接在这里面执行程序。但在共享内存里面寻找编译好的PHP程序时,会在很短的时间内产生一些锁定,所以一个程序可以被多个进程同时执行。不适合放入共享内存的文件将被缓存到硬盘上。

eAccelerator包含了一个PHP加码器和解释器(loader????)。你可以使用encoder.php对你的程序加码,这样在分发程序的时候就可以不给出源码了。加码后的文件可以在任何机子上运行,只要它装有eAccelerator的PHP。加码后的代码不能被恢复,因为它是以编译完了的形式而存储的,而且存储时不包含源码。当然,程序中一些内部的东西可以使用反编译工具(different  reverse  engineering  tools)还原(例如:disassemblers, debuggers等等),但这并不是重要的。

eAccelerator可以和Zend Optimizer的加码器共存。但是在php.ini中Zend Optimizer必须在eAccelerator配置参数的后面。如果你不使用Zend Optimizer的加码器,我们不推荐同时安装Zend Optimizer

eAccelerator不能在CGI模式下运行,但是它能在一些web服务器下的Fast-CGI模式运行,比如:lighttpd。

下面是一些能提供相同作用的产品:
 - Zend Performance Suite (http://www.zend.com/)
 - Alternative PHP Cache (http://pecl.php.net/package/APC)

下载
--------
最新的eAccelerator版本能在下面的页面下载:
http://sourceforge.net/projects/eaccelerator/
版本控制的快照在:
http://snapshots.eaccelerator.net

要求:
--------
apache >= 1.3, mod_php >= 4.1, linux下工具:autoconf, automake, libtool, m4

兼容性:
--------
eAccelerator能与PHP4、PHP5很好的工作,对PHP5.1版本还没很好的兼容。它能使用在Linux, FreeBSD, MacOS X,
Solaris 和 Windows 下的 apache 1.3 and 2, lighttpd 和 IIS.

快速安装:
-------------

你可以在下面的网站上找到更多的安装信息:
http://eaccelerator.sourceforge.net/

注意:在Microsoft Windows下安装,请参考README.win32文件

第一步:编译eaccelerator

  export PHP_PREFIX="/usr"
 
  $PHP_PREFIX/bin/phpize
 
  ./configure \
  --enable-eaccelerator=shared \
  --with-php-config=$PHP_PREFIX/bin/php-config
 
  make

  你必须使用“export”命令指明PHP的安装路径的前缀,它可能是"/usr" "/usr/local",或其它

第二布:安装 eAccelerator

  make install

第三步:配置 eAccelerator

  eAccelerator能做为Zend或PHP的扩展。

对于大于0.9.1版本的eaccelerator,如果你有/etc/php.d目录,你应该复制eaccelerator.ini到里面去,当然你可以根据你的需要修改它。

如果没有,你需要修改你的php.ini文件(通常是/etc/php.ini)

作为Zend的扩展:

  zend_extension="/usr/lib/php4/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.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"

  如果你使用thread safe模式安装的PHP,你应该使用“zend_extension_ts”代替“zend_extension”

作为PHP的扩展:

  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.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"
 
第四步:建立缓存目录

  mkdir /tmp/eaccelerator
  chmod 0777 /tmp/eaccelerator

 

配置选项
--------

eaccelerator.shm_size
 eAccelerator使用共享内存的总数。单位是MB.
 设置为“0”,则为操作系统默认值。默认为“0”

eaccelerator.cache_dir
 硬盘缓存的目录。eAccelerator存储预编译代码,session数据,内容数据(content)和使用的入口(entres??)。这些数据也能够存储在共享内存里(为了得到更快的通道)。默认为“/tmp/eaccelerator”。

 yayu:建立这个空目录后,在有人访问php页面后会自动建立二级二维目录(0,1.....e,f)(16进制,晕)

eaccelerator.enable
 决定eAccelerator是否有效。“1”为有效,“0”为无效。默认为“1”

eaccelerator.optimizer
 是否使用内置的优化工具加速代码的执行。“1”为是,“0”为否。默认为“1”

eaccelerator.debug
 是否记录eAccelerator debug log。“1”为是,“0”为否。默认为“0”

eaccelerator.check_mtime
 是否检查php程序更新时间。“1”为是,“0”为否。如果你想改变php程序后重编译程序到共享内存,那就应该设置为“1”。默认为“1”

eaccelerator.filter
 决定哪些php文件被缓存。你可能需要指定哪些文件(如:"*.php *.phtml")需要被缓存。如果在文件前加上“!”,那么符合条件的文件将被忽略。默认为"",这以为着所有php文件都会被缓存。

eaccelerator.shm_max
 设置诸如“eaccelerator_put()”之类的函数能往共享内存里面加载数据的大小。单位为MB。“0”为不限制,默认为“0”。

eaccelerator.shm_ttl
 当共享内存空间已满,将删除在“shm_ttl”秒前没有使用的程序。默认为0,为不删除任何文件。

eaccelerator.shm_prune_period
 共享内存已满。前一次操作是在shm_prune_period秒之前,那么这一次将删除所有的旧程序。默认为“0”,意为不删除任何程序。

eaccelerator.shm_only
 是否把编译后程序缓存到硬盘上。这个选项对session数据和内容(content)缓存无效。默认为“0”,意为同时使用共享内存和硬盘做缓存。

eaccelerator.compress
 是否对缓存内容做压缩。默认为“1”,为不压缩。

eaccelerator.compress_level
 压缩的级别,默认和最高都为“9”。

eaccelerator.name_space
 一个对所有键值假拟的字符串。通过在.htaccess文件中设置的这个值,允许两个应用使用相同的键值运行在同一个主机上。

 yayu:命名空间?

eaccelerator.keys
eaccelerator.sessions
eaccelerator.content
 决定那些键,session数据和内容将被缓存,这些可能的值是:

 "shm_and_disk" - 缓存数据在共享内存和硬盘上(默认值)
 "shm"          - 缓存数据在共享内存,如果共享内存已满或者提交的数据大小超过eaccelerator.shm_max,则存储在硬盘上。
 "shm_only"     - 只缓存数据在共享内存
 "disk_only"    - 只缓存数据在硬盘
 "none"         - 不缓存数据

eaccelerator.allowed_admin_path
 允许得到管理信息和管理操作的脚本路径。


控制面板及反汇编
---------------

如果你要使用控制面板,你需要在编译eAccelerator时加上 --with-eaccelerator-info选项,这个是默认值。

复制control.php文件到你的跟目录下,并且设置这个路径到php.ini 或者 eaccelerator.ini的eaccelerator.allowed_admin_path选项。如果你不这样做,你将看不到更多的相关信息,也不能控制eAccelerator。

你可以在control.php文件中设置用户名和密码以进入控制面板

当你使用--with-eaccelerator-disassembler编译时,你需要把dasm.php和PHP_Highlight.php也放到control.php目录里面。反汇编需要在编译PHP时加上对tokenizer的支持(--enable-tokenizer)
你可以在dasm.php文件的上面得到执行反汇编时的用户名和密码


eAccelerator 函数
-----------------

函数文档请看: http://bart.eaccelerator.net/doc/phpdoc/

联系我们
--------
当你有疑问、需要补丁,提交bug,请发email给 Bart Vanbrabant

--------------------------

以下是英文全文:

eAccelerator for PHP
=====================

What is eAccelerator?
----------------------
eAccelerator is a free open source PHP  accelerator,  optimizer,  encoder  and
dynamic content cache for PHP. It increases  performance  of  PHP  scripts  by
caching them in compiled state, so that the overhead of  compiling  is  almost
completely eliminated. It also optimises  the  script  to speed  up  execution
of PHP scripts. eAccelerator typically reduces server load and  increases  the
speed of your PHP code by 1-10 times.

eAccelerator is a fork of TurckMMCache
( http://sourceforge.net/project/turckmm-cache/  by Dmitry Stogov )

eAccelerator stores compiled PHP scripts in shared memory  and  executes  code
directly from it. It creates  locks  only  for  short  time,  while  searching
compiled PHP script in the cache, so one script can be executed simultaneously
by several engines. Files that can't fit in shared memory are cached  on  disk
only.

eAccelerator contains a PHP encoder and loader. You  can  encode  PHP  scripts
using encoder.php in order to distribute them without sources.  Encoded  files
can be run on any site which  runs  PHP  with  eAccelerator.  The  sources  of
encoded scripts can't be restored because they are stored in a  compiled  form
and the encoded version doesn't contain the source. Of course, some  internals
of the scripts can  be  restored  with  different  reverse  engineering  tools
(disassemblers, debuggers, etc), but it is not trivial.

eAccelerator is compatible with Zend Optimizer's loader. Zend  Optimizer  must
be installed after eAccelerator in php.ini. If you don't use  scripts  encoded
with  Zend  Encoder  we  do  not  recommend  to  install  Zend  Optimizer with
eAccelerator.

eAccelerator does not work in CGI mode but it does work in Fast-CGI mode with
webservers like lighttpd.


Here are some other products that provide the same functionality:

 - Zend Performance Suite (http://www.zend.com/)
 - Alternative PHP Cache (http://pecl.php.net/package/APC)

Download
--------
Latest eAccelerator versions can be downloaded at the sourceforge page:
http://sourceforge.net/projects/eaccelerator/
Development snapshots from cvs can be downloaded at
http://snapshots.eaccelerator.net


Requirements
------------
apache >= 1.3, mod_php >= 4.1, autoconf, automake, libtool, m4


Compatibility
-------------
eAccelerator has been reported working with php4 and php5, php 5.1 support
hasn't been integrated yet. It is being used on Linux, FreeBSD, MacOS X,
Solaris and Windows with apache 1.3 and 2, lighttpd and IIS.


Quick install
-------------

You can find more information about installation on eAccelerator website.
http://eaccelerator.sourceforge.net/

Note(1): for Microsoft Windows installation, please refer to README.win32 file.

Step 1. Compiling eAccelerator

  export PHP_PREFIX="/usr"
 
  $PHP_PREFIX/bin/phpize
 
  ./configure \
  --enable-eaccelerator=shared \
  --with-php-config=$PHP_PREFIX/bin/php-config
 
  make

  You must specify the real prefix where PHP is installed in the "export"
  command. It may be "/usr" "/usr/local", or something else.

Step 2. Installing eAccelerator

  make install

Step 3. Configuring eAccelerator

eAccelerator can be installed both as Zend or PHP extension.

For eaccelerator > 0.9.1, if you have /etc/php.d directory, you should copy eaccelerator.ini inside and modify default value if you need.

If not, you need to edit your php.ini file (usually /etc/php.ini).

To install as Zend extension:

  zend_extension="/usr/lib/php4/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.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 thread safe build of PHP you must use "zend_extension_ts" instead
  of "zend_extension".

To install as PHP extension:

  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.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" 

Step 4. Creating cache directory

  mkdir /tmp/eaccelerator
  chmod 0777 /tmp/eaccelerator


Configuration Options
---------------------

eaccelerator.shm_size
    The amount of shared memory (in megabytes) that eAccelerator will use.
    "0" means OS default. Default value is "0".

eaccelerator.cache_dir
    The directory that is used for disk cache. eAccelerator stores precompiled
    code, session data, content and user entries  here. The same data  can  be
    stored in shared memory also (for more quick access). Default value is
    "/tmp/eaccelerator".

eaccelerator.enable
    Enables or disables eAccelerator. Should be "1" for enabling  or  "0"  for
    disabling. Default value is "1".

eaccelerator.optimizer
    Enables or disables internal peephole optimizer which may  speed  up  code
    execution. Should be "1" for enabling or "0" for disabling. Default  value
    is "1".

eaccelerator.debug
    Enables or disables debug logging. Should be "1" for enabling or  "0"  for
    disabling. Default value is "0".

eaccelerator.check_mtime
    Enables or disables PHP file modification checking .  Should  be  "1"  for
    enabling or "0" for disabling. You should set it to "1"  if  you  want  to
    recompile PHP files after modification. Default value is "1".

eaccelerator.filter
    Determine which PHP files must be cached. You may specify  the  number  of
    patterns (for example "*.php *.phtml") which specifies to cache or not  to
    cache. If pattern starts with the character "!", it means to ignore  files
    which are matched by the following pattern. Default value is "" that means
    all PHP scripts will be cached.

eaccelerator.shm_max
    Disables putting large values into shared memory by " eaccelerator_put() "
    function. It indicates the largest allowed size in bytes (10240, 10K, 1M).
    The "0" disables the limit. Default value is "0".

eaccelerator.shm_ttl
    When eaccelerator fails to get shared memory for new script it removes all
    scripts which were not accessed  at  last "shm_ttl"  seconds  from  shared
    memory. Default value is "0" that means -  don't  remove  any  files  from
    shared memory.

eaccelerator.shm_prune_period
    When eaccelerator fails to get shared memory for new script  it  tryes  to
    remove  old  script   if   the   previous   try   was   made   more   then
    "shm_prune_period" seconds ago. Default value is "0" that  means  -  don't
    try to remove any files from shared memory.

eaccelerator.shm_only
    Enables or disables caching of compiled scripts on disk. It has  no  effect
    on session data and content caching. Default value is "0" that means -  use
    disk and shared memory for caching.

eaccelerator.compress
    Enables or disables cached content compression. Default value is  "1"  that
    means enable compression.

eaccelerator.compress_level
    Compression level used for content caching.  Default value is "9" which  is
    the maximum value

eaccelerator.name_space
    A string that's prepended to all keys. This allows two applications that
    use the same key names to run on the same host by setting this in .htaccess
    or in the main configuration file for the whole webserver.
   
eaccelerator.keys
eaccelerator.sessions
eaccelerator.content
    Determine where keys, session data and content will be cached. The possible
    values are:
    "shm_and_disk" - cache data in shared memory and on disk (default value)
    "shm"          - cache data in shared memory or on disk if shared memory
                     is full or data size greater then "eaccelerator.shm_max"
    "shm_only"     - cache data in shared memory
    "disk_only"    - cache data on disk
    "none"         - don't cache data

eaccelerator.allowed_admin_path
    The script paths that are allowed to get admin information and do admin
    controls

Control panel and disassembler
------------------------------

If you want to use the control-panel you need to compile eAccelerator with
    --with-eaccelerator-info which is the default value.
You need to copy the control.php file to your webroot and set the path to it
in the php.ini or eaccelerator.ini in the eaccelerator.allowed_admin_path
directive. If you don't do this you wont be able to see much information and
can't control eAccelerator.
You can set the username and password needed to access the control-panel in
the control.php file.

When you compile eAccelerator with --with-eaccelerator-disassembler you need
to place the dasm.php and PHP_Highlight.php file also in the same directory
as the control.php file. The disassembler requires PHP to be compiled with
tokenizer support (--enable-tokenizer).
You can set the username and password needed to access the disassembler at the
top of dasm.php.

eAccelerator API
----------------

API documentation can be found on this website: http://bart.eaccelerator.net/doc/phpdoc/

Contact us
----------
You can contact us with questions, patches or bugs, by sending an email to
Bart Vanbrabant

展开全文  
收起全文