地球上的大熊, 巧遇上火星的你
2011-4-5 [分享]簡單優化php於Apache存取效率
剛才在看一個有關php的talk slide時,發現一個簡單優化php於Apache存取效率的方法。
也許有朋友已經很早就知道了~ 不過熊小真的沒想過這有分別…(果然是要多多看多多學)
於apache setting file內 (e.g. /etc/httpd/conf/httpd.conf)
找
<Directory /var/www>
DirectoryIndex index.htm index.html
</Directory>
改成
<Directory /var/www>
DirectoryIndex index.php index.htm index.html
</Directory>
重點是index.php必須加到最前 (熊小之前是加到htm與html之間), 如果是cgi, pl其實都一樣,加到最前。令apache最先存取。
原理
strace your web server process
[box=#ffffcc]% /usr/sbin/apache2 -X &
[1] 16367
(hit page a few times to warm up caches)
% strace -p 16367 -o sys1.txt
Process 16367 attached - interrupt to quit
(hit page once)
Process 16367 detached
% grep stat sys1.txt | grep -v fstat ...
2011-4-5 10:34 PM - Vic - 9921 觀看 - 2 評論 - 程式開發討論區