给PHP加速,配置和确认eAccelerator使用效率

注本网转载某位大侠的  具体的给忘 了  贴出来共享下

 

 

一、eAccelerator 介绍

  我们知道,php 是属于解释开型语言,他们编写的动态内容都需要解释器来运行,解释器会把代码进行语法分析,然后生成可直接运行的中间代码,这个 中间代码被称为opcodeoperate  code, 每一段php 代码在运行的时候都有一个转换为opcode 的过程,如果一段代码要运行多次的话,opcode 也会生成多次

 eAccelerator 是一个免费开源的PHP 加速的软件, 其原理是通过缓存PHP 代码编译后的opcode 到共享内存中,并在用户访问的时候直接调来提高PHP 脚本的运行效 率,来起到高效的加速作用,对于不能缓存到共享内存中的文件和代码,eAccelerator 还可以把他们缓存到系统磁盘上

通过使用eAccelerator ,可以优化你的PHP 代码执行速度,降低服务器负载。

更多了解看 这里

二、eAccelerator 安装

1 、安装 可以直接看 这里

   wget  http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2

   tar jxvf /root/tools/eaccelerator-0.9.6.tar.bz2

   cd eaccelerator-0.9.6/

   export PHP_PREFIX="/usr/local/php"

   $PHP_PREFIX/bin/phpize

   ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config

   make&&make install

本人强列推荐把要用的软件打包成rpm 易管理,使用方便。

关于如何创建eacceleratorRPM 包,请 参考这里

 

三、eAccelerator 配置

一、eAccelerator 提供了两种配置和调用方式,分别为安装为

 1  Zend extension 模式

       用语句zend_extension= 后面跟加eaccelerator.so 的绝对路径,比如

  zend_extension = /usr/local/php/lib/modules/eaccelerator.so

 2 、安装为 PHP extension 模式,

  则用语句 extension=”eaccelerator.so”   就可以 其它的配置一样

二、php 调用到eaccelerator.so 的方法也可以有两种

  方法一,直接在php.ini 文件的任意位置里面添加和下面eaccelerator.ini  一样的语句

  方法二:编绎php 时如果加了 –with-config-file-scan-dir=/etc/php.d  (或其它目录)则  直接可以用vi  eaccelerator.ini  。然后放入相应目录,其内容如下:

; Enable eAccelerator extension module

zend_extension = /usr/local/php/lib/modules/eaccelerator.so

; Options for the eAccelerator module

eaccelerator.shm_size = 0

eaccelerator.enable = 1

eaccelerator.optimizer = 1

eaccelerator.check_mtime = 1

eaccelerator.filter = ""

eaccelerator.shm_max = 0

eaccelerator.shm_ttl = 3600

eaccelerator.shm_prune_period = 0

eaccelerator.shm_only = 0

eaccelerator.compress = 1

eaccelerator.compress_level = 9

eaccelerator.keys = "shm_and_disk"

eaccelerator.sessions = "shm_and_disk"

eaccelerator.content = "shm_and_disk"

eaccelerator.debug = 9

eaccelerator.allowed_admin_path=/usr/local/apache2/htdocs/eaccelerator/

eaccelerator.cache_dir = "/tmp/eaccelerator"

eaccelerator.log_file = "/tmp/eaccelerator.log"

  更多详细及语句解释可以直接看 这里

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

mkdir /tmp/eaccelerator

chmod 777 /tmp/eaccelerator

四、确认eaccelerator 已配置成功

  如果你的机器上有php 命令,则直接用php -v 就会看到

  PHP 5.2.13 (cli) (built: Apr 21 2010 22:38:51)

  Copyright (c) 1997-2010 The PHP Group

  Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

     with eAccelerator v0.9.6, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

如果没有php 命令,则可以在写一个info.php 的文件,内容为 ,在浏览器里打开你的info.php 文件,也会看到eAccelerator 相应的信息

以上两种办法都能帮你确认eAccelerator 已正确配置

四、安装eAccelerator control panel control.php

   把解开的eAccelerator 的源码包里的control.php 文件复制到你的WEB 服务器中的一个目录下,使其它以通过http 访问,如本例中 http://10.20.0.199/eaccelerator/control.php    还记得在前面配置eaccelerator 时有一个选项,这个选项的作用就是充许你通过control.php 看到更多的相关信息和能控制eAccelerator    eaccelerator.allowed_admin_path

要打开control.php 文件,你需要输入默认的用户名admin 和密码eAccelerator 这个用户名和密码可以在control.php 文件里修改。

  二、这个控制面板有两大主要功能

  一:控制eAccelerator 的功能如禁用或者启用eaccelerator 的缓存和优化作用,删除缓存的内容等
 
二:是查看已经缓存过的文件

五、eAccelerator 配置后效果测试

    在开始之前我要先明一个服务器的并发处理问题,一般我们量化服务器的处理能力时会用到一个词吞吐率(throughput ),单位是“reqs/s” 这个词还用于描述如网络通讯数据量等,但这里只用于描述服务器的并发。

   还需要了解一下ab 的使用 如果之前不了解, 可以看这里   ····

  这里重点关注ab 报告里requests per second   如下:

   .... 截去 .....

Document Path:          /index.php

Document Length:        47459 bytes

 

Concurrency Level:      100

Time taken for tests:   43.394 seconds

Complete requests:      10000

Failed requests:        0

Write errors:           0

Total transferred:      476070979 bytes

HTML transferred:       474650695 bytes

Requests per second:    230.44 [#/sec] (mean)

Time per request:       433.945 [ms] (mean)

Time per request:        4.339 [ms] (mean, across all concurrent requests)

Transfer rate:          10713.65 [Kbytes/sec] received

   .... 截去 .....

测试及取值方法,这里我们直接用index.php 脚本. 里面的内容为 ab 并发100 ,请求10000 次来取得服务器的吞吐。然后对不安装和安装eaccelerator 分别取下的服务器的吞吐的值进行对比。来确定 eaccelerator 加速效用

注意: 为了排除网络响应等其它的因素我建义ab 命令的测试就在本机运行
            
为了数据的有效性,建议多次运行ab 命令,然后取得一个比较平均的值

一、不安装eaccelerator 的测试数据

ab -c 100 -n 10000  http://10.20.0.199/index.php

Document Path:          /index.php

Document Length:        39630 bytes

 

Concurrency Level:      100

Time taken for tests:   8.031 seconds

Complete requests:      10000

Failed requests:        0

Write errors:           0

Total transferred:      397744576 bytes

HTML transferred:       396324434 bytes

Requests per second:    1245.19 [#/sec] (mean)

Time per request:       80.309 [ms] (mean)

Time per request:       0.803 [ms] (mean, across all concurrent requests)

Transfer rate:          48366.09 [Kbytes/sec] received

 

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    1   2.0      0      20

Processing:    13   79   8.2     80     104

Waiting:        7   76  11.1     79     100

Total:         20   80   7.5     80     104

 

Percentage of the requests served within a certain time (ms)

二、安装eaccelerator 的测试数据

ab -c 100 -n 10000  http://10.20.0.199/index.php

Document Path:          /index.php

Document Length:        42147 bytes

 

Concurrency Level:      100

Time taken for tests:   6.378 seconds

Complete requests:      10000

Failed requests:        0

Write errors:           0

Total transferred:      423038785 bytes

HTML transferred:       421618217 bytes

Requests per second:    1567.89 [#/sec] (mean)

Time per request:       63.780 [ms] (mean)

Time per request:       0.638 [ms] (mean, across all concurrent requests)

Transfer rate:          64773.36 [Kbytes/sec] received

 

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.6      0       8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Discuz! X的config_global.php配置文件的注释教程: ```php <?php /** * Discuz! X - 配置文件 * * 版权所有 (C) 2001-2019 Comsenz Inc. * This is NOT a freeware, use is subject to license terms * * $Id: config_global.php 36360 2019-11-18 00:28:51Z nemohou $ */ // ---------------------------- CONFIG DB ----------------------------- // /** * 数据库设置 * * type 数据库类型,可选值为 mysql 或 mysqli * server 数据库服务器 * port 数据库端口 * username 数据库用户名 * password 数据库密码 * dbname 数据库名 * pconnect 是否启用持久连接 * charset 数据库字符集,可选值为 gbk, big5, utf8, latin1, etc. * setnames 是否将字符集强制设为 utf8 * tablepre 表名前缀 * dbdebug 是否启用数据库调试模式 */ $_config['db']['1']['dbtype'] = 'mysql'; $_config['db']['1']['dbhost'] = 'localhost'; $_config['db']['1']['dbport'] = '3306'; $_config['db']['1']['dbuser'] = 'root'; $_config['db']['1']['dbpw'] = 'password'; $_config['db']['1']['dbname'] = 'discuz'; $_config['db']['1']['pconnect'] = '0'; $_config['db']['1']['charset'] = 'utf8'; $_config['db']['1']['setnames'] = '1'; $_config['db']['1']['tablepre'] = 'pre_'; $_config['db']['1']['dbdebug'] = 'false'; // -------------------------- CONFIG MEMORY --------------------------- // /** * 内存变量缓存设置 * * type 缓存类型,可选值为 filecache 或 memcache 或 apc * ttl 缓存失效时间,单位为秒 * prefix 缓存前缀,建议修改,避免同服务器中的程序引起冲突 * servers memcache 缓存服务器地址和端口,可指定多个,格式为数组 */ $_config['memory']['prefix'] = 'discuz_'; $_config['memory']['eaccelerator'] = false; $_config['memory']['apc'] = false; $_config['memory']['xcache'] = false; $_config['memory']['file']['server'] = array(); $_config['memory']['memcache']['server'] = array( array('127.0.0.1', 11211, 1), // 第一个参数为 memcache 服务器的地址,第二个参数为端口,第三个参数为权重,用于负载均衡,默认为1 ); // ----------------------------- CONFIG CACHE --------------------------- // /** * 数据缓存设置 * * type 缓存类型,可选值为 filecache 或 memcache 或 apc * ttl 缓存失效时间,单位为秒 * prefix 缓存前缀,建议修改,避免同服务器中的程序引起冲突 * filecache 设置缓存的目录,仅对 filecache 缓存有效 * servers memcache 缓存服务器地址和端口,可指定多个,格式为数组 * compress 是否启用 memcache 的压缩功能 */ $_config['cache']['type'] = 'filecache'; $_config['cache']['file']['server'] = array( array('localhost', 11211, 1), ); $_config['cache']['memcache']['server'] = array( array('localhost', 11211, 1), ); $_config['cache']['apc'] = false; $_config['cache']['ttl'] = 0; $_config['cache']['prefix'] = 'discuz_'; $_config['cache']['file']['dir'] = './data/cache/'; $_config['cache']['memcache']['compress'] = false; // ----------------------------- CONFIG SMTP --------------------------- // /** * 邮件设置 * * maildefault 默认的邮件发送方式,可选值为 smtp 或 sendmail * smtp 以下 SMTP 设置仅在 maildefault 为 smtp 时有效 * server SMTP 服务器地址 * port SMTP 服务器端口 * auth 是否启用 SMTP 认证,可选值为 true 或 false * username SMTP 服务器用户名 * password SMTP 服务器密码 * sendmail 以下 Sendmail 设置仅在 maildefault 为 sendmail 时有效 * server Sendmail 服务器地址 * sendmail_path Sendmail 程序路径 * * 注意:不同的邮件发送方式对应的设置选项不同,具体请参见官方文档 */ $_config['mail']['maildefault'] = 'smtp'; $_config['mail']['smtp']['server'] = 'smtp.exmail.qq.com'; $_config['mail']['smtp']['port'] = '25'; $_config['mail']['smtp']['auth'] = '1'; $_config['mail']['smtp']['username'] = '[email protected]'; $_config['mail']['smtp']['password'] = 'password'; $_config['mail']['sendmail']['server'] = '/usr/sbin/sendmail'; $_config['mail']['sendmail']['sendmail_path'] = ''; // ----------------------------- CONFIG SECURITY --------------------------- // /** * 安全设置 * * authkey 论坛加密密钥,建议修改,长度为 64 个字符 * cookiepre cookie 前缀,建议修改,避免同服务器中的程序引起冲突 * cachelist 缓存前缀列表,建议修改,避免同服务器中的程序引起冲突 * attackevasive 是否启用防抵制攻击功能,可选值为 0、1、2、3 或 4 * 0 表示关闭防抵制攻击功能 * 1 表示启用 cookie 刷新方式防抵制攻击功能 * 2 表示启用限制代理访问功能防抵制攻击功能 * 3 表示启用 cookie 刷新与限制代理访问两种方式的防抵制攻击功能 * 4 表示启用加强版防抵制攻击功能 * 注意:启用加强版防抵制攻击功能后,可能会影响网站的访问速度 * admincp_allow_ip 允许访问后台的 IP 地址列表,多个 IP 之间用英文逗号隔开 * admincp_check_ip 是否启用后台 IP 验证功能,可选值为 0 或 1 * admincp_cpsession 是否启用后台 session 验证功能,可选值为 0 或 1 */ $_config['security']['authkey'] = '1234567890123456789012345678901234567890123456789012345678901234'; $_config['security']['cookiepre'] = 'discuz_'; $_config['security']['cachelist'] = ''; $_config['security']['attackevasive'] = '0'; $_config['security']['admincp_allow_ip'] = ''; $_config['security']['admincp_check_ip'] = '1'; $_config['security']['admincp_cpsession'] = '1'; // ----------------------------- CONFIG SYSTEM --------------------------- // /** * 系统设置 * * debug 是否启用调试模式,可选值为 true 或 false * cookie_domain cookie 作用域 * cookie_path cookie 作用路径 * attachdir 附件上传目录,相对于论坛根目录的路径 * attachurl 附件 URL 地址 * attachimgpost 是否允许在帖子中显示图片附件,可选值为 0 或 1 * attachrefcheck 是否检查附件引用,可选值为 0 或 1 * attachsave 是否在服务器上保存上传的附件,可选值为 0 或 1 * attachimgmaxsize 图片类附件上传大小,单位为字节 * attachimgthumb 是否生成缩略图,可选值为 0 或 1 * attachimgquality 缩略图质量,取值范围为 1-100 * attachimgwatermark 是否添加水印,可选值为 0 或 1 * attachimgwatermarktype 水印类型,可选值为 text、image 或 none * attachimgwatermarktext 水印文字,当水印类型为 text 时有效 * attachimgwatermarktrans 水印透明度,取值范围为 1-100,当水印类型为 text 时有效 * attachimgwatermarkfile 水印图片文件名,当水印类型为 image 时有效 * attachimgwatermarkpos 水印位置,可选值为 1-9,当水印类型为 image 时有效 * refererhotlink 是否开启防盗链功能,可选值为 0 或 1 * hotlink_protect_key 防盗链密钥,如果不设置,则系统自动生成一个密钥 */ $_config['debug'] = false; $_config['cookie']['cookie_domain'] = ''; $_config['cookie']['cookie_path'] = '/'; $_config['attachdir'] = './data/attachment'; $_config['attachurl'] = 'attachment/'; $_config['attachimgpost'] = '1'; $_config['attachrefcheck'] = '1'; $_config['attachsave'] = '1'; $_config['attachimgmaxsize'] = '2048000'; $_config['attachimgthumb'] = '1'; $_config['attachimgquality'] = '80'; $_config['attachimgwatermark'] = '1'; $_config['attachimgwatermarktype'] = 'text'; $_config['attachimgwatermarktext'] = 'Discuz!'; $_config['attachimgwatermarktrans'] = '50'; $_config['attachimgwatermarkfile'] = ''; $_config['attachimgwatermarkpos'] = '9'; $_config['refererhotlink'] = '0'; $_config['hotlink_protect_key'] = ''; // ----------------------------- CONFIG OUTPUT --------------------------- // /** * 输出设置 * * output_gzip 是否启用 Gzip 压缩输出,可选值为 0 或 1 * output_charset 输出页面字符集,可选值为 gb2312、gbk、big5、utf-8 或 iso-8859-1 * output_language 输出页面语言,可选值为 en、zh-cn、zh-tw * output_encoding 输出页面编码格式,可选值为 xml、html、xhtml */ $_config['output']['gzip'] = '0'; $_config['output']['charset'] = 'utf-8'; $_config['output']['language'] = 'zh-cn'; $_config['output']['encoding'] = 'html'; ``` 以上就是Discuz! X的config_global.php配置文件的注释教程,希望能够帮助到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值