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,macos x, solaris, aix en hp-ux。
2、系统要求
php4 or php5 autoconf automake libtool //开源代码phpfensi测试数据 m4eaccelerator 只支持使用 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- //开源代码phpfensi测试数据 config= $php_prefix /bin/php-config #make #make install4、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测试数据press= "1" eaccelerator测试数据press_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测试数据press= "1" eaccelerator测试数据press_level= "9"有关php.ini文件的详细配置说明,请参照源码目录的readme文档或者访问官方文档,完成安装配置后,我们最后要创建缓存目录.
#mkdir /tmp/eaccelerator
#chmod 777 /tmp/eaccelerator
测试 :php代码中使用eaccelerator加速,下面有一个测试的代码,你可以测试一下eaccelerator强大的威力,该代码在cli 模式下可能无效,代码如下:
<?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" ; //开源代码phpfensi测试数据 } echo $tt ->pro; $tt ->func(); $tt ->now(time() + 86400); ?>查看更多关于eAccelerator加速php程序 - php高级应用的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did30091