使用 eAccelerator加速PHP代碼的目的
更新時(shí)間:2007年03月16日 00:00:00 作者:
使用 eAccelerator加速PHP代碼
eAccelerator 真是一個(gè)好東西(它的前身是truck-mmcache)。
簡(jiǎn)單來(lái)講它是一套配合PHP(支持PHP5)運(yùn)作的緩存系統(tǒng),通過(guò)共享內(nèi)存或磁盤文件方式交換數(shù)據(jù)。
它被廣為使用的是PHP源碼“編碼”(不太貼切的稱為“加密”)和緩存PHP執(zhí)行的中間碼以加速。關(guān)于 eA 的安裝使用的文章已經(jīng)很多而且也很詳細(xì)了,這次我想推薦的是用它輔助程序設(shè)計(jì)緩存,它提供了一組API如下:
是一個(gè)非常便捷而又穩(wěn)定的本機(jī)緩存實(shí)現(xiàn)方式,目前這部分設(shè)計(jì)似乎只支持于共享內(nèi)存,所以只能用于 Unix -Like OS 了,windows的就沒(méi)這個(gè)福氣了。
1. eaccelerator_put($key, $value, $ttl=0)
將 $value 以 $key 為鍵名存進(jìn)緩存(php4下支持對(duì)像類型,看源碼好像zend2里不支持了),$ttl 是這個(gè)緩存的生命周期,單位是秒,省略該參數(shù)或指定為 0 表示不限時(shí),直到服務(wù)器重啟清空為止。
2. eaccelerator_get($key)
根據(jù) $key 從緩存中返回相應(yīng)的 eaccelerator_put() 存進(jìn)去的數(shù)據(jù),如果這項(xiàng)緩存已經(jīng)過(guò)期或不存在那么返回值是 NULL
3. eaccelerator_rm($key)
根據(jù) $key 移除緩存
4. eaccelerator_gc()
移除清理所有已過(guò)期的 key
5. eaccelerator_lock($key)
為 $key 加上鎖定操作,以保證多進(jìn)程多線程操作時(shí)數(shù)據(jù)的同步。需要調(diào)用 eaccelerator_unlock($key) 來(lái)釋放這個(gè)鎖或等待程序請(qǐng)求結(jié)束時(shí)自動(dòng)釋放這個(gè)鎖。
例如:
<?php
eaccelerator_lock("count");
eaccelerator_put("count",eaccelerator_get("count")+1));
?>
6. eaccelerator_unlock($key)
根據(jù) $key 釋放鎖
7. eaccelerator_cache_output($key, $eval_code, $ttl=0)
將 $eval_code 代碼的輸出緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put)
For Example:
<?php eaccelerator_cache_output('test', 'echo time(); phpinfo();', 30); ?>
8. eaccelerator_cache_result($key, $eval_code, $ttl=0)
將 $eval_code 代碼的執(zhí)行結(jié)果緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put),類似 cache_output
For Example:
<?php eaccelerator_cache_result('test', ' time() . "Hello";', 30); ?>
9. eaccelerator_cache_page($key, $ttl=0)
將當(dāng)前整頁(yè)緩存 $ttl 秒。
For Example:
<?php
eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
echo time();
phpinfo();
?>
10. eaccelerator_rm_page($key)
刪除由 eaccelerator_cache_page() 執(zhí)行的緩存,參數(shù)也是 $key
______________________________________________
(作個(gè)簡(jiǎn)單例子看看它的威力,注意在 cli 模式下可能無(wú)效?。?nbsp;
<?php
class test_cache {
var $pro = 'hello';
function test_cache() {
echo "Object Created!<br>\n";
}
function func() {
echo ', the world!';
}
function now($t) {
echo date('Y-m-d H:i:s', $t);
}
}
$tt = eaccelerator_get("test_tt");
if (!$tt)
{
$tt = new test_cache;
eaccelerator_put("test_tt", $tt);
echo "no cached!<br>\n";
}
else {
echo "cached<br>\n";
}
echo $tt->pro;
$tt->func();
$tt->now(time() + 86400);
?>
以下是網(wǎng)友的評(píng)論:
--------------------------------------------------------------------------------
showsa 回復(fù)于:2005-12-31 19:51:56win 也支持! http://www.arnot.info/eaccelerator/
信天翁 回復(fù)于:2006-01-04 17:17:37最新版 eAccelerator 0.9.4-rc1 中有個(gè)小bug 表現(xiàn)為 /var/log/httpd/error_log 出現(xiàn)大量 [warn] (32)Broken pipe: write pipe_of_death 的錯(cuò)誤信息 解決方法 修改 debug.c 文件 ----------------------------------------------- /** * Close the debug system. */ void ea_debug_shutdown () { fflush (F_fp); // 源語(yǔ)句, 關(guān)閉文件時(shí)沒(méi)有檢測(cè)文件句柄 //fclose (F_fp); //改為 if (F_fp != stderr) fclose (F_fp); F_fp = NULL; }
soichiro 回復(fù)于:2006-01-10 22:01:21eAccelerator/truck-mmcache太恐怖了,我現(xiàn)在有兩個(gè)負(fù)載很高的系統(tǒng),一個(gè)基于Drupal,另一個(gè)基于PostNuke,用了eAccelerator后,Drual速度提升100倍,PostNuke提升10倍,PostNuke提升比較少是因?yàn)樗旧砭秃芸?
wangyih 回復(fù)于:2006-04-08 10:48:11和使用squid比怎么樣
showsa 回復(fù)于:2006-04-08 23:23:44怎么去和 squid去比啊 不一樣的東西 squid是緩存頁(yè)面運(yùn)行結(jié)果 如果不是實(shí)時(shí)顯示,squid肯定強(qiáng)了 但是論壇之類的,squid就不行了,用eaccelerator /memcache 可以很大程度上提升效率
Yarco 回復(fù)于:2006-04-09 10:00:43但是據(jù)說(shuō)和encode過(guò)的代碼有沖突啊... 不知道現(xiàn)在的和zend的兼容性如何?
eAccelerator 真是一個(gè)好東西(它的前身是truck-mmcache)。
簡(jiǎn)單來(lái)講它是一套配合PHP(支持PHP5)運(yùn)作的緩存系統(tǒng),通過(guò)共享內(nèi)存或磁盤文件方式交換數(shù)據(jù)。
它被廣為使用的是PHP源碼“編碼”(不太貼切的稱為“加密”)和緩存PHP執(zhí)行的中間碼以加速。關(guān)于 eA 的安裝使用的文章已經(jīng)很多而且也很詳細(xì)了,這次我想推薦的是用它輔助程序設(shè)計(jì)緩存,它提供了一組API如下:
是一個(gè)非常便捷而又穩(wěn)定的本機(jī)緩存實(shí)現(xiàn)方式,目前這部分設(shè)計(jì)似乎只支持于共享內(nèi)存,所以只能用于 Unix -Like OS 了,windows的就沒(méi)這個(gè)福氣了。
1. eaccelerator_put($key, $value, $ttl=0)
將 $value 以 $key 為鍵名存進(jìn)緩存(php4下支持對(duì)像類型,看源碼好像zend2里不支持了),$ttl 是這個(gè)緩存的生命周期,單位是秒,省略該參數(shù)或指定為 0 表示不限時(shí),直到服務(wù)器重啟清空為止。
2. eaccelerator_get($key)
根據(jù) $key 從緩存中返回相應(yīng)的 eaccelerator_put() 存進(jìn)去的數(shù)據(jù),如果這項(xiàng)緩存已經(jīng)過(guò)期或不存在那么返回值是 NULL
3. eaccelerator_rm($key)
根據(jù) $key 移除緩存
4. eaccelerator_gc()
移除清理所有已過(guò)期的 key
5. eaccelerator_lock($key)
為 $key 加上鎖定操作,以保證多進(jìn)程多線程操作時(shí)數(shù)據(jù)的同步。需要調(diào)用 eaccelerator_unlock($key) 來(lái)釋放這個(gè)鎖或等待程序請(qǐng)求結(jié)束時(shí)自動(dòng)釋放這個(gè)鎖。
例如:
<?php
eaccelerator_lock("count");
eaccelerator_put("count",eaccelerator_get("count")+1));
?>
6. eaccelerator_unlock($key)
根據(jù) $key 釋放鎖
7. eaccelerator_cache_output($key, $eval_code, $ttl=0)
將 $eval_code 代碼的輸出緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put)
For Example:
<?php eaccelerator_cache_output('test', 'echo time(); phpinfo();', 30); ?>
8. eaccelerator_cache_result($key, $eval_code, $ttl=0)
將 $eval_code 代碼的執(zhí)行結(jié)果緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put),類似 cache_output
For Example:
<?php eaccelerator_cache_result('test', ' time() . "Hello";', 30); ?>
9. eaccelerator_cache_page($key, $ttl=0)
將當(dāng)前整頁(yè)緩存 $ttl 秒。
For Example:
<?php
eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
echo time();
phpinfo();
?>
10. eaccelerator_rm_page($key)
刪除由 eaccelerator_cache_page() 執(zhí)行的緩存,參數(shù)也是 $key
______________________________________________
(作個(gè)簡(jiǎn)單例子看看它的威力,注意在 cli 模式下可能無(wú)效?。?nbsp;
<?php
class test_cache {
var $pro = 'hello';
function test_cache() {
echo "Object Created!<br>\n";
}
function func() {
echo ', the world!';
}
function now($t) {
echo date('Y-m-d H:i:s', $t);
}
}
$tt = eaccelerator_get("test_tt");
if (!$tt)
{
$tt = new test_cache;
eaccelerator_put("test_tt", $tt);
echo "no cached!<br>\n";
}
else {
echo "cached<br>\n";
}
echo $tt->pro;
$tt->func();
$tt->now(time() + 86400);
?>
以下是網(wǎng)友的評(píng)論:
--------------------------------------------------------------------------------
showsa 回復(fù)于:2005-12-31 19:51:56win 也支持! http://www.arnot.info/eaccelerator/
信天翁 回復(fù)于:2006-01-04 17:17:37最新版 eAccelerator 0.9.4-rc1 中有個(gè)小bug 表現(xiàn)為 /var/log/httpd/error_log 出現(xiàn)大量 [warn] (32)Broken pipe: write pipe_of_death 的錯(cuò)誤信息 解決方法 修改 debug.c 文件 ----------------------------------------------- /** * Close the debug system. */ void ea_debug_shutdown () { fflush (F_fp); // 源語(yǔ)句, 關(guān)閉文件時(shí)沒(méi)有檢測(cè)文件句柄 //fclose (F_fp); //改為 if (F_fp != stderr) fclose (F_fp); F_fp = NULL; }
soichiro 回復(fù)于:2006-01-10 22:01:21eAccelerator/truck-mmcache太恐怖了,我現(xiàn)在有兩個(gè)負(fù)載很高的系統(tǒng),一個(gè)基于Drupal,另一個(gè)基于PostNuke,用了eAccelerator后,Drual速度提升100倍,PostNuke提升10倍,PostNuke提升比較少是因?yàn)樗旧砭秃芸?
wangyih 回復(fù)于:2006-04-08 10:48:11和使用squid比怎么樣
showsa 回復(fù)于:2006-04-08 23:23:44怎么去和 squid去比啊 不一樣的東西 squid是緩存頁(yè)面運(yùn)行結(jié)果 如果不是實(shí)時(shí)顯示,squid肯定強(qiáng)了 但是論壇之類的,squid就不行了,用eaccelerator /memcache 可以很大程度上提升效率
Yarco 回復(fù)于:2006-04-09 10:00:43但是據(jù)說(shuō)和encode過(guò)的代碼有沖突啊... 不知道現(xiàn)在的和zend的兼容性如何?
您可能感興趣的文章:
- php 提速工具eAccelerator 配置參數(shù)詳解
- 在Windows下編譯適用于PHP 5.2.12及5.2.13的eAccelerator.dll(附下載)
- PHP加速 eAccelerator配置和使用指南
- 使用eAccelerator加密PHP程序
- 使用 eAccelerator加速PHP代碼的方法
- 實(shí)現(xiàn)php加速的eAccelerator dll支持文件打包下載
- 用windows下編譯過(guò)的eAccelerator for PHP 5.1.6實(shí)現(xiàn)php加速的使用方法
- win2003服務(wù)器之用Zend和eAccelerator在IIS6下同時(shí)加速
相關(guān)文章
php 使用file_get_contents讀取大文件的方法
本文介紹了在php中使用file_get_contents函數(shù)讀取大文件的方法,并附上了示例以及使用小技巧,非常的實(shí)用,這里推薦給大家2014-11-11php創(chuàng)建類并調(diào)用的實(shí)例方法
在本篇文章里小編給大家分享的是關(guān)于php如何創(chuàng)建類并調(diào)用的相關(guān)知識(shí)點(diǎn),有需要的朋友們可以學(xué)習(xí)下。2019-09-09PHP中實(shí)現(xiàn)中文字符進(jìn)制轉(zhuǎn)換原理分析
中文字符編碼研究系列第四期,PHP實(shí)現(xiàn)中文字符進(jìn)制轉(zhuǎn)換原理分析,主要討論中文漢字轉(zhuǎn)換為十進(jìn)制和十六進(jìn)制的方法,并掌握轉(zhuǎn)換原理應(yīng)用于實(shí)際開發(fā)。本文以GBK編碼字符為例,討論GBK編碼的字符轉(zhuǎn)換原理2011-12-12PHP中冒號(hào)、endif、endwhile、endfor使用介紹
下面的一些用法,對(duì)于相當(dāng)一部分PHP愛(ài)好者來(lái)說(shuō)根本沒(méi)見過(guò)啊,這些是什么東西呢?2010-04-04php實(shí)現(xiàn)無(wú)限級(jí)分類查詢(遞歸、非遞歸)
這篇文章分為兩種情況,介紹了在遞歸和不使用遞歸的情況下PHP實(shí)現(xiàn)無(wú)限級(jí)分類,感興趣的小伙伴們可以參考一下2016-03-03PHP遠(yuǎn)程連接oracle數(shù)據(jù)庫(kù)操作實(shí)現(xiàn)方法圖文詳解
這篇文章主要介紹了PHP遠(yuǎn)程連接oracle數(shù)據(jù)庫(kù)操作實(shí)現(xiàn)方法,結(jié)合圖文形式詳細(xì)分析了php連接Oracle數(shù)據(jù)庫(kù)的相關(guān)配置、實(shí)現(xiàn)方法、遇到的問(wèn)題、解決方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-04-04