正在加载...
分页: 9/12 第一页 上页 4 5 6 7 8 9 10 11 12 下页 最后页 [ 显示模式: 摘要 | 列表 ]

安装apc为php加速

[ 2009/07/21 12:25 | by selboo ]
Alternative PHP Cache(APC)是 PHP 的一个免费公开的优化代码缓存。它用来提供免费,公开并且强健的架构来缓存和优化 PHP 的中间代码。
主要是加速PHP..
WordPress是一个占用内存的大户,而且执行效率比较低..
我安装了APC后,VPS的整体内存降了30M左右吧..
下面是安装方法:

wget http://pecl.php.net/get/APC-3.1.2.tgz
tar zxvf APC-3.1.2.tgz
cd APC-3.1.2/
/usr/local/php/bin/phpize
./configure --enable-apc --enable-apc-mmap --with-php-config=/usr/local/php/bin/php-config
make
make install


配置php.ini 末尾修改加入

[code]extension_dir = &qu
Tags: , , ,

PHP版iis日志分析程序

[ 2009/06/10 01:36 | by selboo ]

<?php
/*******************************************************
*功能:iis日志分析,分析出访问IP总数,搜索引擎抓取次数
*说明:
*       将日志文件放在网站根目录,并改名为log.log。
*演示:http://www.zhanzhangpu.com/tools/iislog/
*       http://www.zhanzhangpu.com/tools/iislog/demo.gif
*作者:blackli,来自落伍者
*问题:搜索引擎蜘蛛地址不准确,尤其是google蜘蛛地址,国内流行的地址列
*       表存在相当大的误差,能力有限,不能够解决这个问题。有兴趣的可以参考
*       下面的网址.
*参考:http://www.seonewthing.com/googleBotCheck.aspx
*       http://googlewebmastercentral.blogspot.com/2006/09/how-to-verify-googlebot.html
*******************************************************/

        //打开日志文件
        $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
        $fp = fopen("$DOCUMENT_ROOT/log.log",'rb');
        if ( !$fp )
        {
                echo '打开文件失败';
                exit;
        }

        //分析每行日志
        $num_ip = 0;    //访问IP总数
        $ip = array();    //IP数据数组,其中ip[$i][0]为IP地址、ip[$i][1]为该地址出现次数
        while ( !feof($fp) )
        {
                $line = fgets($fp,1001);
                if ( substr($line,0,1) == '#' )
                {
                        //获取日志生成时间
                        if ( substr($line,0,5) == '#Date' )
                        {
                                $date_info = explode(' ',$line);
                                //echo '日志生成时间:'.$date_info[1].'  '.$date_info[2].'</br>';
                        }
                }
                else
                {
                        //获取访问IP
                        if ( $line == '' ) continue;
                        $ip_info = explode(' ',$line);

                        for ( $j = $num_ip-1, $having_ip = false; $j >= 0 ; $j -- )
                        {
                                if ( $ip[$j][0] == $ip_info[6] )
                                {
                                        $having_ip = true;
                                        $ip[$j][1] ++ ;
                                        break;
                                }
                        }
                        if ( $having_ip == false )
                        {
                                $ip[$num_ip][0] = $ip_info[6];
                                $ip[$num_ip][1] = 1;
                                $num_ip ++;
                        }
                }
        }

        //获取搜索引擎蜘蛛访问次数
        //baidu、google蜘蛛地址列表
        $baiduSpider = array('220.181','159.226','202.108','61.135.');
        $googleBot = array('74.125.','209.85.','66.102.','64.233.','64.249','209.85.');

        $num_Spider = $num_googleBot = 0;
        for ( $i = 0; $i < $num_ip ; $i++ )
        {
                //计算百度蜘蛛访问次数
                for ( $j = 0 ; $j < 4 ; $j ++ )
                {

                        if ( substr($ip[$i][0],0,7) == $baiduSpider[$j] )
                        {
                                $num_Spider += $ip[$i][1];
                                continue;
                        }
                }
                //计算google蜘蛛访问次数
                for ( $j = 0 ; $j < 6 ; $j ++ )
                {
                        if ( substr($ip[$i][0],0,7) == $googleBot[$j] )
                        {
                                $num_googleBot += $ip[$i][1];
                                continue;
                        }
                }
        }

        //echo '百度蜘蛛请求'.$num_Spider.'次
';
        //echo 'google蜘蛛请求'.$num_googleBot.'次
';
        fclose($fp);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iis日志分析-Powered by ZhanZhangPu</title>
<style type="text/css">
#main{
        width:800px;
        margin:0 auto;
        border:1px solid #EEE;
}
#main div{
        background:#EEE;
        border:2px solid #FBFBFB;
        line-height:25px;
        font-size:15px;
        padding:15px;
}
</style>
</head>
<body >
<div id="main">
        <h2>日志生成时间<?php echo $date_info[1].'  '.$date_info[2]; ?></h2>
        <div>
                共有<?php echo $num_ip; ?>IP的请求.

                百度蜘蛛请求<?php echo $num_Spider; ?>次.

                google蜘蛛请求<?php echo $num_googleBot; ?>次.
        </div>
        <div>
                IP地址列表:

                <?php
                        for ( $i = 0 ; $i < $num_ip ; $i ++ )
                        {
                                echo $ip[$i][0].'     '.$ip[$i][1].'次.
';
                        }
                ?>
        </div>
        <div>Powered by <a href="http://www.zhanzhangpu.com">站长铺</a>&trade;</div>
</div>
</body>
</html>
Tags: ,

最小化安装PHP

[ 2009/05/22 13:42 | by selboo ]
from:http://jackywdx.cn/2009/05/install_php_minimum/

在研究PHP内核的时候,每次改动源代码都得重新编译PHP,每次编译都得费上好一段时间,如果只是想调试内核而不需要PHP的其他功能,可以把PHP的绝大部分模块都去掉,这样编译速度就会快很多。我用了下面的configure配置:
./configure –prefix=/usr/local/php5.2.9_2 –disable-xmlwriter –disable-xmlreader –disable-tokenizer –disable-simplexml –disable-posix –disable-dom –disable-ctype –disable-hash –disable-json –disable-filter –disable-xml –without-pear –disable-cgi –disable-pdo –disable-libxml –without-iconv –disable-spl –without-sqlite –disable-session –disable-reflection
这样编译出来的PHP其他就没有加载任何模块了,编译速度也快了不少。不过还可以改造编译的时候的环境检查,现在还不知道如何改造,等知道了再贴上来。
刚刚发现一个问题,configure只需要运行一次就够了,运行之后会生成Makefile文件,记录了一些配置选项,下次修改源文件的时候再重新编译的时候只需要运行make && make install就可以了
make install的时候会安装不少文件:
Installing PHP CLI binary: /usr/local/php5.2.9_2/bin/
Installing PHP CLI man page: /usr/local/php5.2.9_2/man/man1/
Installing build environment: /usr/local/php5.2.9_2/lib/php/build/
Installing header files: /usr/local/php5.2.9_2/include/php/
Installing helper programs: /usr/local/php5.2.9_2/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php5.2.9_2/man/man1/
page: phpize.1
page: php-config.1
但我只需要生成 php程序就可以,修改Makefile文件
install_targets = install-cli install-build install-headers install-programs
找到这一行,然后把这一行注释掉,再增加一行:
install_targets = install-cli
这样每次make install的时候就只要安装生成PHP程序了。
呵呵,这样速度快了N多。

做优化用的上了,针对自己的环境,需要什么就enable
Tags: ,

php.ini 中文版

[ 2009/05/16 14:50 | by selboo ]
[PHP]
; PHP还是一个不断发展的工具,其功能还在不断地删减
; 而php.ini的设置更改可以反映出相当的变化,
; 在使用新的PHP版本前,研究一下php.ini会有好处的

;;;;;;;;;;;;;;;;;;;
; 关于这个文件 ;
;;;;;;;;;;;;;;;;;;;

; 这个文件控制了PHP许多方面的观点。为了让PHP读取这个文件,它必须被命名为
; 'php.ini'。PHP 将在这些地方依次查找该文件:当前工作目录;环境变量PHPRC
; 指明的路径;编译时指定的路径。
; 在windows下,编译时的路径是Windows安装目录。
; 在命令行模式下,php.ini的查找路径可以用 -c 参数替代。

; 该文件的语法非常简单。空白字符和用分号';'开始的行被简单地忽略(就象你可能
; 猜到的一样)。 章节标题(例如 : [Foo])也被简单地忽略,即使将来它们可能
; 有某种的意义。 <
Tags: ,
一、PHP加速器介绍

      PHP加速器是一个为了提高PHP执行效率,从而缓存起PHP的操作码,这样PHP后面执行就不用解析转换了,可以直接调用PHP操作码,这样速度上就提高了不少。

      Apache中使用mod_php的请求、响应执行流程:

1、Apache接收请求。
2、Apache传递请求给mod_php。
3、mod_php定位磁盘文件,并加载到内存中。
4、mod_php编译源代码成为opcode树。
5、mod_php执行opcode树。

      PHP加速器相应的就是第四步,它的目的就是防止PHP每次请求都重复编译PHP代码,因为在高访问量的网站上,大量的编译往往没有执行速度快呢?所以这里面有个瓶颈就是PHP的重复编译既影响了速度又加载了服务器负载,为了解决此问题,PHP加速器就这样诞生了。

二、PHP加速器安装与配置

1、安装配置APC

      APC全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”,它是PHP PECL中的一个扩展,好像是facebook在使用它,下面开始安装(ubuntu环境):      

01.$wget http://pecl.php.net/get/APC-3.0.19.tgz
$tar xvzf APC-3.0.19.tgz
$cd APC-3.0.19/APC-3.0.19
$/usr/local/php/bin/phpize
$./configure –enable-apc –enable-apc-mmap –with-php-config=/usr/local/php/bin/php-config
$make
$sudo make install


下面我们再配置APC,因为我的PECL扩展路径改变了,所以我得移动下编译好的文件:


$sudo mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/apc.so /usr/local/php/lib/php/extensions/PECL


      然后我们再编辑php.ini文件进行配置,请把下面的代码加入到php.ini中即可:

extension_dir = "/usr/local/php/lib/php/extensions/PECL"
extension = apc.so
; APC
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64
apc.optimization = 1
apc.num_files_hint = 0
apc.ttl = 0
apc.gc_ttl = 3600
apc.cache_by_default = on


      这样重启apache就会在phpinfo()信息中显示。

2、安装配置eAccelerator

      eAccelerator的前身其实是truck-mmcache,因为开发truk-mmcache的人被Zend给招安了,所以开发eAccelerator的人继承了truk-mmcache的一些特性,设计出eAccelerator加速器。安装如下:

01.$wget http://jaist.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.bz2
02.$tar -jxf eaccelerator-0.9.5.tar.bz2
03.$cd eaccelerator-0.9.5
04.$/usr/local/php/bin/phpize
05.$./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
06.$make
07.$sudo make install
08.$sudo mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so /usr/local/php/lib/php/extensions/PECL


      将下面代码加入php.ini文件中


01.extension = eaccelerator.so
02.; eAccelerator
03.eaccelerator.shm_size = "16"
04.eaccelerator.cache_dir = "/tmp/eaccelerator"
05.eaccelerator.enable = "1"
06.eaccelerator.optimizer = "1"
07.eaccelerator.check_mtime = "1"
08.eaccelerator.debug = "0"
09.eaccelerator.filter = ""
10.eaccelerator.shm_max = "0"
11.eaccelerator.shm_ttl = "0"
12.eaccelerator.prune_period = "0"
13.eaccelerator.shm_only = "0"
14.eaccelerator.compress = "1"
15.eaccelerator.compress_level = "9"
      

      创建缓存目录,重启apache

01.$sudo mkdir /tmp/eaccelerator
02.$sudo chmod 777 /tmp/eaccelerator
03.$sudo /usr/local/apache/apachectl restart


      在phpinfo()检查是否安装成功.

3、安装配置XCache

      XCache作为国人自己开发的东西,做小菜鸟的我也感到骄傲,而且XCache无论在速度还是性能上都做的不错。下面就赶紧让我们品尝它吧!


01.$wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
02.$tar xvzf xcache-1.2.2.tar.gz
03.$cd xcache-1.2.2
04.$/usr/local/php/bin/phpize
05.$./configure –enable-xcache –enable-xcache-coverager –with-php-config=/usr/local/php/php-config
06.$make
07.$sudo make install
08.$sudo mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so /usr/local/php/lib/php/extensions/PECL


      在php.ini添加配置信息:


01.extension = xcache.so
02.; xcache
03.xcache.admin.user = "admin"
04.xcache.admin.pass = "(执行) echo ’(你的密码)’|md5sum(得出的密文)"
05.;
06.xcache.size = 24M
07.xcache.shm_scheme = "mmap"
08.xcache.count = 2
09.xcache.slots = 8k
10.xcache.ttl = 0
11.xcache.gc_interval = 0
12.
13.xcache.var_size = 8M
14.xcache.var_count = 1
15.xcache.var_slots = 8k
16.xcache.var_ttl = 0
17.xcache.var_maxttl = 0
18.xcache.var_gc_interval = 300
19.xcache.test = Off
20.xcache.readonly_protection = On
21.xcache.mmap_path = "/tmp/xcache"
22.xcache.coredump_directory = ""
23.xcache.cacher = On
24.xcache.stat = On
25.xcache.optimizer = Off
26.;
27.xcache.coverager = On
28.xcache.coveragedump_directory = ""


      创建缓存目录,重启apache


01.$sudo mkdir /tmp/xcache
02.$sudo chmod 777 /tmp/xcache
03.$sudo /usr/local/apache/bin/apachectl restart


      去查看phpinfo()信息吧!

三、PHP加速器测试

1、测试环境

硬件:   AMD Athlon 64 X2 Dual Core Processor 4400+ @ 2.2GHz  CPU,  2GB 内存. 160GB SATA 硬盘
软件:   Linux Ubuntu server Gutsy 7.10, Apache 2.2.4, MySQL 5.0.45 和 PHP 5.2.3
测试指令:  ab -c5 -n3000 http://example.com/    
(我们使用的是Apache Benchmark (ab) 工具,并发连接为5,3000次请求)

2、测试结果

无任何加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   288.255212 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    10.41 [#/sec] (mean)
11.Time per request:       480.425 [ms] (mean)
12.Time per request:       96.085 [ms] (mean, across all concurrent requests)
13.Transfer rate:          226.23 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.5      0      19
17.Processing:   181  479 186.0    444    1822
18.Waiting:      166  461 184.7    427    1708
19.Total:        181  479 186.0    444    1822
20.Percentage of the requests served within a certain time (ms)
21.50%    444
22.66%    525
23.75%    577
24.80%    619
25.90%    732
26.95%    819
27.98%    946
28.99%   1012
29.100%   1822 (longest request)  
    

APC加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   98.530068 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    30.45 [#/sec] (mean)
11.Time per request:       164.217 [ms] (mean)
12.Time per request:       32.843 [ms] (mean, across all concurrent requests)
13.Transfer rate:          661.84 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.0      0       2
17.Processing:    58  163  71.2    155    2452
18.Waiting:       53  158  69.6    150    2329
19.Total:         58  163  71.2    155    2452
20.Percentage of the requests served within a certain time (ms)
21.50%    155
22.66%    178
23.75%    193
24.80%    204
25.90%    235
26.95%    258
27.98%    285
28.99%    302
29.100%   2452 (longest request)  


eAccelerator加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   95.983986 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    31.26 [#/sec] (mean)
11.Time per request:       159.973 [ms] (mean)
12.Time per request:       31.995 [ms] (mean, across all concurrent requests)
13.Transfer rate:          679.39 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.1      0       3
17.Processing:    57  159  91.3    148    3830
18.Waiting:       50  152  89.8    142    3704
19.Total:         57  159  91.3    148    3830
20.Percentage of the requests served within a certain time (ms)
21.50%    148
22.66%    174
23.75%    193
24.80%    205
25.90%    239
26.95%    263
27.98%    289
28.99%    309
29.100%   3830 (longest request)


      XCache加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   99.76300 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    30.28 [#/sec] (mean)
11.Time per request:       165.127 [ms] (mean)
12.Time per request:       33.025 [ms] (mean, across all concurrent requests)
13.Transfer rate:          658.19 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.0      0       2
17.Processing:    59  164  83.4    155    3367
18.Waiting:       52  156  66.4    148    1802
19.Total:         59  164  83.4    155    3367
20.Percentage of the requests served within a certain time (ms)
21.50%    155
22.66%    178
23.75%    196
24.80%    206
25.90%    237
26.95%    263
27.98%    287
28.99%    305
29.100%   3367 (longest request)  


3、结果摘要

请求时间(秒) 单次请求时间(毫秒) 最大内存占用(MB) 最小内存占用(MB)
None  10.41            96.08                  24                              24
APC 30.45               32.84                  21                              21
eAccelerator 31.26   31.99                  23                              18
XCache 30.28          33.02                  29                              19

四、PHP加速器比较结果总结

     1、通过测试得出eAccelerator在请求时间和内存占用综合方面是最好的。
     2、通过测试得出使用加速器比无加速器在请求时间快了3倍左右。
     3、通过各个官方观察,XCache是更新最快的,这也说明最有发展的。

      以上是总结结果,你也许会问我到底用那个加速器好呢?我只能告诉你,首先,用一定比不用好,其次每个加速器还有一些可以调优的参数,所以要根据你的系统环境而定,然后,我个人觉得你可以详细研究下eAccelerator和XCache,这两款潜力还是很大的,最后我从比较专业的测试网站搞了一张结果图:
点击在新窗口中浏览此图片
分页: 9/12 第一页 上页 4 5 6 7 8 9 10 11 12 下页 最后页 [ 显示模式: 摘要 | 列表 ]