linux 下 完整複製硬碟或無痛換硬碟 以CentOS為例

linux 下 完整複製硬碟或無痛換硬碟 以CentOS為例

一台Centos主機,硬碟出現了壞軌,要更換硬碟。無痛同步備份兩顆硬碟的操作:
1.裝上新硬碟,開機,進入系統。
2.fdisk -l ; 由於兩顆硬碟都是Sata的,所以fdisk -l出來的結果是sda(舊) sdb(新)
3.dd if=/dev/sda of=/dev/sdb ; 注意的是最好兩顆硬碟是同容量和同型號,否則比較麻煩。
等待,漫長的等待,直到結束。
4.關機,將兩個排線換一下。
5.finish

dd的方式有點類似ghost的整顆複製,速度較慢,但不會出現ghost那樣無法啓動的現象。
新的硬碟也不需要先分割或格式化,他會很徹底的複製磁碟區,所以建議兩顆同款。
製作linux的軟raid1也可以嘗試用這種方式同步。

PS:dd過程中如果無聊,可以通過在另一個終端鍵入 killall -s SIGUSR1 dd 發送SIGUSR1信號獲取當前進度

CentOS 5.10 釋出

CentOS 5.10 釋出

111720704

前幾天才發現,原來CentOS 釋出了 5.10 版!

5.10版 內建支援 php53,太好了!這樣就不用自己找資源去安裝php53了,

還是用CentOS 5.X的朋友們,趕快yum update 升級啦~

CentOS 5 更新 php 5.3以上

CentOS 5 更新 php 5.3以上

先移除原本的php mysql

yum remove php* mysql*

 

更新套件

wget http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

安裝新的

yum –enablerepo=remi install php53 php53-cli php53-common php53-gd php53-imap php53-intl php53-mbstring php53-mysql php53-odbc php53-pdo php53-pspell php53-snmp php53-xml php53-xmlrpc mysq mysql-server

收工

============

等待測試:

1.不知道mysql是不是一定要移除和重新安裝?!

測試結果: 不行,mysql要移除。 建議一開始安裝CENTOS 5.9時就不要裝PHP和MYSQL相關

CentOS6 with CutyCapt

CentOS6 with CutyCapt

vi /etc/yum.repos.d/atrpms.repo
[atrpms]
name=CentOS $releasever – $basearch – ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1

[atrpms-testing]
name=CentOS $releasever – $basearch – ATrpms testing
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/testing
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1

yum install qt47 qt47-devel qt47-webkit qt47-webkit-devel
yum -y install subversion
yum -y install gcc+ gcc-c++
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
vi /etc/profile
export QTDIR=/usr/lib64/qt47
export QTLIB=/usr/lib64/qt47/lib
export QTINC=/usr/lib64/qt47/include
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PATH=$QTDIR/bin:$PATH

mv cutycapt/CutyCapt /usr/local/cutycapt
cd /usr/local/cutycapt
qmake
make

wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt
mv ./xvfb-run.sh.txt /usr/local/cutycapt/xvfb-run.sh
chmod u+x /usr/local/cutycapt/xvfb-run.sh
yum install xorg-x11-server-Xvfb
yum install cjkuni-ukai-fonts cjkuni-uming-fonts -y

CentOS 安裝cutycapt 二

CentOS 安裝cutycapt 二

CutyCapt作爲IECapt的兄弟,可以跨平臺運行,生成的文件格式也多,SVG、PDF、 PS、 PNG、 JPEG,、TIFF,、GIF和BMP,CutyCap依賴于Qt。
一,先安裝Qt47
增加qt47的下載源
vi /etc/yum.repos.d/atrpms.repo
[atrpms]
name=CentOS $releasever – $basearch – ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1

[atrpms-testing]
name=CentOS $releasever – $basearch – ATrpms testing
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/testing
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1
#yum update
yum install qt47
yum install qt47-devel
yum install qt47-webkit
yum install qt47-webkit-devel
可能的錯誤:
warning: qt44-x11-4.4.3-10_4.el5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID 66534c2b
解决:
yum -y installqt-devel*
可能的錯誤:某些衝突conflict
qt47-x11 conflicts with qt-x11
qt47-x11 conflicts with qt-x11
解决:通過yum remove 卸載衝突的內容
yum remove qt-devel
yum remove qt-x11
二,安裝 CutyCapt
下載代碼,這裏需要用到SVN,如果沒有安裝,可以使用命令安裝:
#yum install subversion
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
mv cutycapt/CutyCapt /usr/local/cutycapt
cd /usr/local/cutycapt
qmake
可能會出現的錯誤:
-bash: qmake: command not found
解决:
qmake-qt47
make
此處可能會報錯:
make: *** [CutyCapt] Error 1
解决:
yum update sqlite #如果是6.0,默認就是3.6
再次執行make即可!
三、下載和安裝X-Server
wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt
mv ./xvfb-run.sh.txt /usr/local/cutycapt/xvfb-run.sh
chmod u+x /usr/local/cutycapt/xvfb-run.sh
出現錯誤提示:CutyCapt: cannot connect to X server :99
可以使用命令安裝:
yum install xorg-x11-server-Xvfb
四,安裝中文包
yum install fonts-chinese
五,運行 CutyCapt進行截圖:執行以下命令,如果沒有錯誤,就會在當前目錄下面保存截圖。
/usr/local/cutycapt/xvfb-run.sh –server-args=”-screen 0, 1024x768x24″ /usr/local/cutycapt/CutyCapt –url=http://www.163.com –out=163.jpg
六 ,其他一些相關問題
Q:出現-bash: xvfb-run: command not found 或 xauth : command not found
安裝 yum install Xorg xauth xorg-x11-fonts*(Xorg,xauth,xorg-x11-fonts* 這是三個不同的工具,每個都需要單獨運行yum install來安裝)
Q:錯誤提示:”mktemp: too few X’s in template `Xauthority’.”
找到 AUTHFILE=$(mktemp -p “$XVFB_RUN_TMPDIR” Xauthority)
修改爲:AUTHFILE=$(mktemp -p “$XVFB_RUN_TMPDIR” Xauthority.XXXXXXXX)
Q:錯誤提示:CutyCapt: cannot connect to X server :99
確認server-args參數是否正確,修改xvfb-run.sh脚本中SERVERNUM=99 改爲SERVERNUM=0
Q:截出來的圖片沒有中文字,需要安裝中文字體
yum install cjkuni-ukai-fonts cjkuni-uming-fonts -y
Q:由于截屏的是整個網站的頁面,只需要第一屏幕
convert -crop 1024×768+0+0 163.jpg 1632.jpg
Q:縮小圖片
convert -resize 40%x40% 1632.jpg 1632.jpg
Q:CutyCapt: cannot connect to X server
網上很多都是要在裝個xvfb-run.sh的,其它不用這麽麻煩
echo “export DISPLAY=’:1.0′” >> /etc/profile
source /etc/profile
vncserver
# ./CutyCapt –help
不過每次都輸入export LIBXCB_ALLOW_SLOPPY_LOCK=1有點麻煩,大神給了個解决方法!
cat > run
vi run
輸入
export LIBXCB_ALLOW_SLOPPY_LOCK=1
../../xvfb-run.sh ./CutyCapt –url=$1 –out=$2 –body-string=$3
保存退出
chmod +x ./run
./run http://www.baidu.com test.jpg, utf-8
依次輸入 $1 http://www.baidu.com $2 圖片名 $3字體
Q:環境變量配置
# vi /etc/profile 未尾加入以下代碼
export QTDIR=/usr/lib/qt44
export QTLIB=/usr/lib/qt44/lib
export QTINC=/usr/lib/qt44/include
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PATH=$QTDIR/bin:$PATH
# source /etc/profile

CenOS with CutyCapt

CenOS with CutyCapt

一 安裝QT44

二 把安裝QT44目錄寫到環境參數中

三 下載軟體編譯安裝

四 安裝x-server

五 Dbug

安裝QT44解碼器居然有三種方法

1. rmp包安裝

2. 增加源安裝

3. Centos 6.X 直接yum安裝更新版確實方便

rpm 安裝

安裝 QT44 解碼器
(x86)
wget http://ftp.riken.go.jp/Linux/atrpms/el5-i386/atrpms/testing/qt44-4.4.3-10_4.el5.i386.rpm
wget http://ftp.riken.go.jp/Linux/atrpms/el5-i386/atrpms/testing/qt44-x11-4.4.3-10_4.el5.i386.rpm
wget http://ftp.riken.go.jp/Linux/atrpms/el5-i386/atrpms/testing/qt44-devel-4.4.3-10_4.el5.i386.rpm

(x64)
wget http://dl.atrpms.net/el5-x86_64/atrpms/testing/qt44-4.4.3-10_4.el5.x86_64.rpm
wget http://dl.atrpms.net/el5-x86_64/atrpms/testing/qt44-x11-4.4.3-10_4.el5.x86_64.rpm
wget http://dl.atrpms.net/el5-x86_64/atrpms/testing/qt44-devel-4.4.3-10_4.el5.x86_64.rpm

rpm -ivh qt44-4.4.3-10*
rpm -ivh qt44-x11-4.4.3-10*
rpm -e qt-devel –nodeps –allmatches
rpm -ivh qt44-devel-4.4.3-10*
rpm -rebuilddb

這一步如果不成功的話應該是各種依賴的問題

可以安裝 qt-devel 依賴包
yum install libXi-devel
yum install libXinerama-devel

也許這裏還會有報錯提示

warning: qt44-x11-4.4.3-10_4.el5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID 66534c2b
error: Failed dependencies:
libGLU.so.1()(64bit) is needed by qt44-x11-4.4.3-10_4.el5.x86_64
libmng.so.1()(64bit) is needed by qt44-x11-4.4.3-10_4.el5.x86_64

執行代碼:

yum -y install qt-devel*

提示依賴什麼就裝什麼。

可以用 yum search packName 來找有沒有這個包

如:yum search qt-devel

如果結果結果有包,那麼安裝時上執行 yum -y install qt-devel* 安裝,加*號是為了安裝上它所有的依賴包

增加源安裝

CentOS 5.x 安裝教程如下:

Add this to /etc/yum.repos.d/CentOS-Base.repo
#ATrpms
[atrpms]
name= CentOS-$releasever – ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/testing
gpgcheck=1
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
enabled=1

rpm –import http://packages.atrpms.net/RPM-GPG-KEY.atrpms
yum install subversion qt47-devel qt47-webkit gcc-c++ qt47-webkit-devel sqlite
centos 6.x安裝

安裝gc-c++

yum install gcc-c++

安裝Qt依懶

yum install qt

yum install qt-devel

安裝的目錄在:

/usr/lib64/qt4

qmake 可以用 /usr/lib64/qt4/bin/qmake 執行

環境變數配置

加入 QT 目錄到環境參數中 如果是32位元系統刪除下面紅字的64
vim /etc/profile
#==================================================
export QTDIR=/usr/lib64/qt44
export QTLIB=/usr/lib64/qt44/lib
export QTINC=/usr/lib64/qt44/include
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PATH=$QTDIR/bin:$PATH
#==================================================

保存退出後,運行一次該檔

source /etc/profile

編譯程序

% svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt (沒有svn的yum install subversion)h
% cd cutycapt/CutyCapt
% qmake
% make

如果沒有X server的話需要使用xvfb-run:

wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt

mv ./xvfb-run.sh.txt ./xvfb-run.sh

chmod u+x ./xvfb-run.sh

./xvfb-run.sh –server-args=”-screen 0, 1024x768x24″ /home/xxx/cutycapt/CutyCapt/CutyCapt –url=http://www.163.com –out=163.jpg
dbug

qmake

make

出現以下錯誤

/usr/lib64/qt47/libQtWebKit.so: undefined reference to `sqlite3_prepare16_v2′

/usr/lib64/qt47/libQtWebKit.so: undefined reference to `sqlite3_column_value’

collect2: ld returned 1 exit status

make: *** [CutyCapt] Error 1

解決:

yum update sqlite

再次執行

make

如果還不成功

qmake-qt47
再次執行make

以下表示make成功

[root@localhost CutyCapt]# make

g++ -Wl,-O1 -o CutyCapt CutyCapt.o moc_CutyCapt.o -L/usr/lib64/qt47 -lQtWebKit -lQtSvg -L/usr/lib64/qt47 -lQtGui -lQtNetwork -lQtCore -lpthread

執行

xvfb-run –server-args=”-screen 0, 1024x768x24″ ./CutyCapt –url=http://www.baidu.com/ –out=localfile1.png –body-string=utf-8

出現-bash: xvfb-run: command not found

安裝

yum install Xorg Xvfb xauth xorg-x11-fonts*

不知道為什麼安裝後 沒有自動生成xvfb-run

下載並上傳xvfb-run腳本到

/usr/bin

chmod +x xvfb-run

運行 ../../xvfb-run.sh ./CutyCapt –url=http://www.baidu.com/ –out=localfile1.png –body-string=utf-8

Locking assertion failure. Backtrace:

#0 /usr/lib/libxcb-xlib.so.0 [0x114737]

#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_unlock+0x31) [0x114891]

#2 /usr/lib/libX11.so.6 [0xc1d021]

#3 /usr/lib/libXfixes.so.3(XFixesQueryVersion+0x4b) [0x2ddebb]

#4 /usr/lib/qt47/libQtGui.so.4 [0x4f5ad20]

#5 /usr/lib/qt47/libQtGui.so.4(_ZN19QApplicationPrivate9constructEP9_XDisplaymm+0xdf) [0x4ecf15f]

#6 /usr/lib/qt47/libQtGui.so.4(_ZN12QApplicationC1ERiPPcbi+0x8b) [0x4ecfd7b]

#7 ./CutyCapt(_ZN8QWebPage13triggerActionENS_9WebActionEb+0x1838) [0x804bcdc]

#8 /lib/libc.so.6(__libc_start_main+0xdc) [0x326e9c]

#9 ./CutyCapt(_ZN7QObject5eventEP6QEvent+0x15d) [0x804ac21]

CutyCapt: xcb_xlib.c:82: xcb_xlib_unlock: Assertion `c->xlib.lock’ failed.

../../xvfb-run.sh: line 168: 12780 Aborted DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE “$@” 2>&1

BUG描述:
運行用Swing的APP時,會無法啟動,顯示類似於”Assertion `c->xlib.lock’ failed.”的
問題
如Zend Studio和NetBeans無法正常啟動,官方解釋這是由於使用了XCB而不是LibX的緣故
,關鍵就在於assert時,Lock問題。一種解決方案是回去使用libx,另一種則是去掉asse
rt時的檢查。

下面的解決方案可行,(試過。)

[轉]
=======================================
Here’s one explaination:

Re: NB doesn’t work in open suse 10.3 “Assertion `c->xlib.lock’ failed.”
Click to flag this post

by pujansrt Oct 11, 2007; 02:45pm :: Rate this Message: – Use ratings to moder
ate (?)

Reply | Reply to Author | View Threaded | Show Only this Message
This is the solution–> just add this to your Environment
export LIBXCB_ALLOW_SLOPPY_LOCK=1

========================================

也就是運行程式前先運行

export LIBXCB_ALLOW_SLOPPY_LOCK=1

再次運行

xvfb-run –server-args=”-screen 0, 1024x768x24″ ./CutyCapt –url=http://www.baidu.com/ –out=localfile1.png –body-string=utf-8

等一會見到生成了localfile1.png表示成功了

不過每次都輸入

export LIBXCB_ALLOW_SLOPPY_LOCK=1 有點麻煩

大神給了個解決方法

cat > run

vi run

輸入

export LIBXCB_ALLOW_SLOPPY_LOCK=1

../../xvfb-run.sh ./CutyCapt –url=$1 –out=$2 –body-string=$3

保存退出

chmod +x ./run

./run http://www.baidu.com test.jpg, utf-8

依次輸入 $1 http://www.baidu.com $2 圖片名 $3字體

截圖成功

如果中文不能正常顯示的話,需要安裝字體檔

yum install fo nts-chinese

Linux 安裝網站截圖軟體CutyCapt

Linux 安裝網站截圖軟體CutyCapt

一,先安裝Qt47
增加qt47的下載源
vi /etc/yum.repos.d/atrpms.repo
[atrpms]
name=CentOS $releasever – $basearch – ATrpms
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1

[atrpms-testing]
name=CentOS $releasever – $basearch – ATrpms testing
baseurl=http://dl.atrpms.net/el$releasever-$basearch/atrpms/testing
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1
enabled=1

yum update
yum installqt47
yum installqt47-devel
yum installqt47-webkit
yum installqt47-webkit-devel
也許這裏還會有報錯提示
warning: qt44-x11-4.4.3-10_4.el5.x86_64.rpm: Header V4 DSA signature: NOKEY, key ID 66534c2b
error: Failed dependencies:
libGLU.so.1()(64bit) is needed by qt44-x11-4.4.3-10_4.el5.x86_64
libmng.so.1()(64bit) is needed by qt44-x11-4.4.3-10_4.el5.x86_64
解決:
yum -y installqt-devel*

二,安裝 CutyCapt
cd /data0/software
svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
mv cutycapt/CutyCapt /usr/local/cutycapt
cd /usr/local/cutycapt
qmake
make
此處可能會報錯
make: *** [CutyCapt] Error 1
解決:
yum update sqlite
再次執行 make

如果還不成功 qmake-qt47 再次執行make

三,下載x-server

wget http://www.flexthinker.com/wp-content/uploads/2009/11/xvfb-run.sh.txt
mv ./xvfb-run.sh.txt/usr/local/cutycapt/xvfb-run.sh
chmodu+x /usr/local/CutyCapt/xvfb-run.sh

四,安裝中文包
yum installfonts-chinese

五,安裝ImageMagick
yum installImageMagick

六,測試:

/usr/local/cutycapt/xvfb-run.sh –server-args=”-screen 0, 1024x768x24″/usr/local/cutycapt/CutyCapt –url=http://www.163.com –out=/tmp/163.jpg

163.jpg沒有載入出flash

七,下載64位flash插件:
cd /data0/software
#wget http://119.188.72.26/1/ishare.down.sina.com.cn/14036482.so?ssig=YB70Xk7Ph9&Expires=1340899200&KID=sina,ishare&ip=1340777795,114.255.44.&fn=libflashplayer.so
http://ishare.iask.sina.com.cn/f/13659493.html
ll /usr/lib64/mozilla/plugins/
lrwxrwxrwx 1 root root 41 06-27 14:00 libflashplayer.so ->/usr/lib64/flash-plugin/libflashplayer.so
cp /data0/software/libflashplayer.so /usr/lib64/flash-plugin/

測試載入成功

$url=”http://www.baidu.com”;
$imgname=str_replace(‘http://’,”,$url);
$imgname=str_replace(‘https://’,”,$imgname);
$imgname=str_replace(‘.’,’-‘,$imgname);
$out = $imgname.’.png’;
$path = ‘CutyCapt.exe’;
$cmd = “$path –url=$url –out=$out”;
system($cmd);

PHP APC 安裝

PHP APC 安裝

3.1.9 最新穩定版

wget http://pecl.php.net/get/APC
tar -zxf APC-3.0.16.tgz
cd APC-3.0.16
(phpize
(如果phpize出現錯誤表示沒有裝 php-devel, 直接 yum install php-devel)
whereis php-config
得出類似結果 php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
)
自編安裝LAMP
/usr/local/php5/bin/phpize

(
./configure –enable-apc –enable-apc-mmap –with-apxs –with-php-config=/usr/bin/php-config
)
自編安裝LAMP
./configure –enable-apc –enable-apc-mmap -with-apxs=/usr/local/apache/bin/apxs –with-php-config=/usr/local/php5/bin/php-config

make
(如果出現 ‘apc_regex’ has no member named ‘preg’ 表示沒安裝 pcre-devel, 直接 yum install pcre-devel)
make install
Installing shared extensions: /usr/lib64/php/modules/
重新啟動Apache
修改 php.ini
extension=apc.so
apc.enabled=1 # default = 1
apc.shm_segments=1 # default = 1
apc.shm_size=128M # default = 30
apc.ttl=7200 # default = 0
apc.user_ttl=7200 # default = 0
apc.num_files_hint=1024 # default = 1000
apc.mmap_file_mask=/tmp/apc.XXXXXX # default = no value
apc.enable_cli=1 # default = 0

相關參數我們再研究~
存檔
再次Restart Apache
OK

[除錯]
錯誤:PHP Fatal error: Cannot redeclare class
解決:apc.cache_by_default = 0

Linux 下找出大容量檔案

Linux 下找出大容量檔案

VPS容量突然爆了,頓時又找不出是哪個檔案太大。
找了一下實用指令,找出指定的目錄中最大的檔案。

find / -type f -size +50000k -exec ls -lh {} ; | awk ‘{ print $9 “:” $5 }’ //找出大於50MB

find . -type f -size +10000k -exec ls -l {} ; //找出10MB

上面兩個指令都能用。

APC, Alternative PHP Cache [PHP緩存模組]

APC, Alternative PHP Cache [PHP緩存模組]

APC是什麼?這裏做個比較全面的介紹:
APC,全稱是Alternative PHP Cache,官方翻譯叫”可選PHP緩存”,但我個人覺得應該叫”另一個PHP緩存”.因為這個東西如果叫”可選PHP緩存”,容易給人一種可要可不要的,不怎麼有用的錯覺.
APC首頁: http://pecl.php.net/package/apc
目前的版本是3.1.13,通過PECL安裝,需要php4.3.0或更高版本.
APC的安裝:
一般是下載源代碼然後phpize來編譯安裝,安裝完以後在加上php.ini里加上
extension=apc.so
這麼一行就行了.

APC的使用
APC的使用其實倒說不上.APC是個優化器,自安裝之日起,就默默地在後臺為您的PHP應用服務了.您的所有PHP代碼會被緩存起來.

另外,APC可提供一定的記憶體緩存功能.但是這個功能並不是十分完美,有報告說如果頻繁使用APC緩存的寫入功能,會導致不可預料的錯誤.如果想使用這個功能,可以看看apc_fetch,apc_store等幾個與apc緩存相關的函數.
從PHP5.2開始,APC引入了一個小甜餅,解決了困擾大家已久的大檔上傳的進度條問題.具體請http://progphp.com/progress.php
APC的高級使用
1.緩存期限:
APC的緩存分兩部分:系統緩存和用戶資料緩存.
系統緩存是自動使用的,是指APC把PHP檔源碼的編譯結果緩存起來,然後在再次調用時先對比時間標記。如果未過期,則使用緩存代碼運行。默認緩存 3600s(一小時).但是這樣仍會浪費大量CPU時間.因此可以在php.ini中設置system緩存為永不過期(apc.ttl=0).不過如果這樣設置,改運php代碼後需要restart一下您的web伺服器(比如apache…).目前對APC的性能測試一般指的是這一層cache;
用戶資料緩存由用戶在編寫php代碼時用apc_store和apc_fetch函數操作讀取、寫入的.如果量不大的話我建議可以使用一下.如果量大,我建議使用memcache會更好.
如果要享受APC帶來的緩存大檔上傳進度的特性,需要在php.ini中將apc.rfc1867設為1,並且在表單中加一個隱藏域APC_UPLOAD_PROGRESS,這個域的值可以隨機生成一個hash,以確何唯一.具體例子請參見前面給出的鏈結.
2.狀態控制和分析:
APC的源碼包自帶了一個apc.php;您可以將這個檔上傳到web伺服器的某個目錄下,用流覽器訪問,這會顯示當前的狀態.我們可以從這裏的表格分析當前的緩存狀況,作出進一步優化.
apc-info-clublocalhost2.png
這是某test站點的狀態.您可以慢慢分析,這個工具會提供很多有用的工具.比如您可以看到哪些檔經常被包含(訪問),您緩存的哪個變數經常被讀取,或經常被更新等.
最後順便提一句,有獨立報告說,APC的代碼緩存、優化效果要高出zend優化器.就算不是真的,他開源而又免費,實在是一個相當不錯的選擇.