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);
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.