PHP缓冲的免费实现方法
时间:2007-02-17 来源:PHP爱好者
由 徐永久 发表于 2002年02月21日 22:56。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
我们知道 Zend 有免费的优化引擎针对 PHP 而作,但是 FreeLAMP 这次采用的是一个叫做 PHP Accelerator 的缓冲产品。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
我们在 “LAMP 加速” 这篇文章中阐述过加速的几种办法,其中提到了 PHP Accelerator,它的安装方法十分简单,但是需要去他的网站获取一个激活键。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
一、下载:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
http://www.php-accelerator.co.uk/download.php
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
二、获取激活键并安装:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
http://www.php-accelerator.co.uk/activate.php
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
注册自己的 SERVER_NAME 后,你会得到下面的提示:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Your key for www.freelamp.com is 8edfd13946c96309244fcca309415902
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Now you must set the key for www.freelamp.com in your site configuration.
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
For single domains not using virtual hosts
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
The key can be set in the php.ini file as follows:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# PHPA key for www.freelamp.com
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
#
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa.registration_key = 8edfd13946c96309244fcca309415902
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
For domains setup as a virtual host
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Add the key to the domain specific section for your web server.
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# www.freelamp.com VHost entry
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
#
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
<VirtualHost 10.20.30.40>
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
ServerName www.freelamp.com
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# ... (other vhost specific config)
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# php settings
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.registration_key 8edfd13946c96309244fcca309415902
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# also enable phpa if set to off in the php.ini (the default is on)
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa 1
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
</VirtualHost>
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
</code>
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
具体的 phpa 值的设置,可以参考软件随带的 CONFIGURATION 文件的配置。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
由于大多数网站是虚拟主机配置,所以,建议采用 php_value phpa. 的方式设置。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
例如:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.tweaks off
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.cache_dir /tmp
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.file_perms 400
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.ignore_files "/index.php, /a/test.php"
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# php_value phpa.ignore_dirs "/data/WWW/site1/,/cache/"
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.shm_size 8
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.shm_key 0xc0deb00
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.shm_perms 664
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
三、设置 php.ini
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
假设我们把下载后的文件解开到 /usr/local/php ,那么在 php.ini 中加入:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
zend_extension=/usr/local/php/php_accelerator_1.2p2.so
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
并注释掉原来的 Zend 优化引擎:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# zend_extension=/usr/local/Zend/lib/ZendOptimizer.so
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
重新启动 Apache ,用浏览器浏览一个任意 PHP 页面可以看到 /tmp 下面生成了一些 phpa 开头的文件。另外一个检查缓冲是否起作用的办法是看 phpinfo() 的输出,原来的 Zend 优化引擎的说明部分,已经被显示成:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
This program makes use of the Zend scripting Language Engine:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Zend Engine v1.1.1, Copyright (c) 1998-2001 Zend Technologies
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
with the PHP Accelerator v1.2p2, Copyright (c) 2001-2002, by Nick Lindridge
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
需要说明的是,安装 INSTALL 安装说明上的办法,其中的 .so 文件和真实的 .so 文件有差异,所以,你在安装的时候需要注意到这个区别。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
四、调整缓冲大小
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
PHP Accelerator 提供了缓冲管理命令:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa_cache_admin -mv 观察内存的缓冲情况
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa_cache_admin -fv 观察文件的缓冲情况
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa_cache_admin -k 设置缓冲大小
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
五、总结
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
该软件提供的 INSTALL 文件阐述了关于性能上的一些说法,笔者不在这里赘述。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
需要说明的是,FreeLAMP.com 的文章目前不是 PHP 架构的,但是论坛系统是 PHP 架构的,所以性能上的提升只会是论坛系统的提升。
php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
我们知道 Zend 有免费的优化引擎针对 PHP 而作,但是 FreeLAMP 这次采用的是一个叫做 PHP Accelerator 的缓冲产品。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
我们在 “LAMP 加速” 这篇文章中阐述过加速的几种办法,其中提到了 PHP Accelerator,它的安装方法十分简单,但是需要去他的网站获取一个激活键。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
一、下载:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
http://www.php-accelerator.co.uk/download.php
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
二、获取激活键并安装:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
http://www.php-accelerator.co.uk/activate.php
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
注册自己的 SERVER_NAME 后,你会得到下面的提示:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Your key for www.freelamp.com is 8edfd13946c96309244fcca309415902
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Now you must set the key for www.freelamp.com in your site configuration.
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
For single domains not using virtual hosts
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
The key can be set in the php.ini file as follows:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# PHPA key for www.freelamp.com
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
#
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa.registration_key = 8edfd13946c96309244fcca309415902
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
For domains setup as a virtual host
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Add the key to the domain specific section for your web server.
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# www.freelamp.com VHost entry
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
#
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
<VirtualHost 10.20.30.40>
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
ServerName www.freelamp.com
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# ... (other vhost specific config)
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# php settings
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.registration_key 8edfd13946c96309244fcca309415902
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# also enable phpa if set to off in the php.ini (the default is on)
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa 1
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
</VirtualHost>
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
</code>
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
具体的 phpa 值的设置,可以参考软件随带的 CONFIGURATION 文件的配置。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
由于大多数网站是虚拟主机配置,所以,建议采用 php_value phpa. 的方式设置。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
例如:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.tweaks off
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.cache_dir /tmp
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.file_perms 400
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.ignore_files "/index.php, /a/test.php"
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# php_value phpa.ignore_dirs "/data/WWW/site1/,/cache/"
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.shm_size 8
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.shm_key 0xc0deb00
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
php_value phpa.shm_perms 664
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
三、设置 php.ini
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
假设我们把下载后的文件解开到 /usr/local/php ,那么在 php.ini 中加入:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
zend_extension=/usr/local/php/php_accelerator_1.2p2.so
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
并注释掉原来的 Zend 优化引擎:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
# zend_extension=/usr/local/Zend/lib/ZendOptimizer.so
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
重新启动 Apache ,用浏览器浏览一个任意 PHP 页面可以看到 /tmp 下面生成了一些 phpa 开头的文件。另外一个检查缓冲是否起作用的办法是看 phpinfo() 的输出,原来的 Zend 优化引擎的说明部分,已经被显示成:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
This program makes use of the Zend scripting Language Engine:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
Zend Engine v1.1.1, Copyright (c) 1998-2001 Zend Technologies
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
with the PHP Accelerator v1.2p2, Copyright (c) 2001-2002, by Nick Lindridge
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
需要说明的是,安装 INSTALL 安装说明上的办法,其中的 .so 文件和真实的 .so 文件有差异,所以,你在安装的时候需要注意到这个区别。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
四、调整缓冲大小
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
PHP Accelerator 提供了缓冲管理命令:
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa_cache_admin -mv 观察内存的缓冲情况
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa_cache_admin -fv 观察文件的缓冲情况
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
phpa_cache_admin -k 设置缓冲大小
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
五、总结
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
该软件提供的 INSTALL 文件阐述了关于性能上的一些说法,笔者不在这里赘述。
wwww.chin aitpower.comSWTnAGleqpZys54sCBei4akrl
需要说明的是,FreeLAMP.com 的文章目前不是 PHP 架构的,但是论坛系统是 PHP 架构的,所以性能上的提升只会是论坛系统的提升。
php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
相关阅读 更多 +