Home php教程 PHP源码 eAccelerator加速php程序

eAccelerator加速php程序

Jun 08, 2016 pm 05:25 PM
eaccelerator nbsp php quot

<script>ec(2);</script>

eaccelerator加速php教程程序

什么是eaccelerator

概念:
eaccelerator 是一个免费开源的php加速、优化、编译和动态缓存的项目,它可以

通过缓存php代码编译后的结果来提高php脚本的性能,使得一向很复杂和离我们很

远的php脚本编译问题完全得到解决。通过使用eaccelerator,可以优化你的php代

码执行速度,降低服务器负载,可以提高php应用执行速度最高达10倍。

原理:
eaccelerator 通过把经过编译后的php代码缓存到共享内存中,并在用户访问的时

候直接调用从而起到高效的加速作用。它的效率非常高,从创建共享内存到查找编

译后的代码都在非常短的时间内完成,对于不能缓存到共享内存中的文件和代码,

eaccelerator还可以把他们缓存到系统磁盘上。
eaccelerator 同样还支持php代码的编译和解释执行,你可以通过encoder.php脚本

来对php代码进行编译达到保护代码的目的,经过编译后的代码必须运行在安装了

eaccelerator的环境下。eaccelerator编译后的代码不能被反编译,它不象其他一

些编译工具那样可以进行反编译,这将使得代码更加安全和高效。
注意:在共享内存里面寻找编译好的php程序时,会在很短的时间内产生一些锁定,

所以一个程序可以被多个进程同时执行。不适合放入共享内存的文件将被缓存到硬

盘上

eaccelerator安装配置

1、支持平台
由于aaccelerator提供了大部分基于共享内存的api,所以在*nix的平台上将得到更

好的支持,虽然也发布了基于windows平台的binary版本,但我在这里就只提供基于

*nix平台的配置和说明,目前可以支持的平台包括linux, freebsd, openbsd, mac

os x, solaris, aix en hp-ux。

2、系统要求
php4 or php5
autoconf
automake
libtool
m4
eaccelerator 只支持使用 mod_php 或者 fastcgi mode 安装的php

3、安装
先去eaccelerator官方下载最新版的源码包:

#tar -zxvf ./eaccelerator-0.9.5-beta2.tar.bz2
#cd eaccelerator-0.9.5-beta2
#export php_prefix="/usr/local" (把php安装目录导入到环境变量,freebsd默

认是/usr/local)
#$php_prefix/bin/phpize
#./configure --enable-eaccelerator=shared --with-php-

config=$php_prefix/bin/php-config
#make
#make install
4、ini文件配置
安装完成,下面开始配置php.ini文件,eaccelerator提供了两种配置和调用方式,

分别如下。

安装为 zend extension 模式:

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"
如果你使用了thread safe模式安装的php,你必须使用 “zend_extension_ts” 替

换第一行的 “zend_extension”.

安装为 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.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"
有关php.ini文件的详细配置说明,请参照源码目录的readme文档或者访问官方文档

完成安装配置后,我们最后要创建缓存目录

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

测试

php代码中使用eaccelerator加速

下面有一个测试的代码,你可以测试一下eaccelerator强大的威力:(该代码在

cli 模式下可能无效)

class test_cache {
  var $pro = 'hello';
 
  function test_cache() {
    echo "object created!
/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!
/n";
}
else {
  echo "cached
/n";
}
 
echo $tt->pro;
$tt->func();
$tt->now(time() + 86400);
?>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles