探討PHP使用eAccelerator的API開(kāi)發(fā)詳解
更新時(shí)間:2013年06月09日 11:14:03 作者:
本篇文章是對(duì)PHP使用eAccelerator的API開(kāi)發(fā)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
1、API和文檔說(shuō)明:
eAccelerator提供了便捷便捷而又穩(wěn)定的本機(jī)緩存實(shí)現(xiàn)方式,由于大部分代碼實(shí)現(xiàn)基于共享內(nèi)存,所以只能在*nix平臺(tái)中使用,Windows平臺(tái)Michael就暫時(shí)不知道何時(shí)有這方面的支持了。
eAccelerator提供如下的API接口和文件:(下述文件均在源碼包的doc/php/目錄下)
文件列表:
cache.php
dasm.php
encoder.php
info.php
loader.php
session.php
shared_memory.php
接口列表:
array eaccelerator_cached_scripts ()
void eaccelerator_cache_output (string $key, string $eval_code, [int $ttl = 0])
void eaccelerator_cache_page (string $key, [int $ttl = 0])
void eaccelerator_cache_result (string $key, string $code, [int $ttl = 0])
void eaccelerator_caching (boolean $flag)
void eaccelerator_clean ()
void eaccelerator_clear ()
array eaccelerator_dasm_file (mixed $filename)
mixed eaccelerator_encode (mixed $src, [mixed $prefix = ''], [string $pre_content = ''], [string $post_content = ''])
void eaccelerator_gc ()
mixed eaccelerator_get (string $key)
array eaccelerator_info ()
array eaccelerator_list_keys ()
void eaccelerator_load ()
boolean eaccelerator_lock (string $key)
void eaccelerator_optimizer (boolean $flag)
void eaccelerator_purge ()
boolean eaccelerator_put (string $key, mixed $value, [int $ttl = 0])
array eaccelerator_removed_scripts ()
boolean eaccelerator_rm (string $key)
void eaccelerator_rm_page (string $key)
boolean eaccelerator_set_session_handlers ()
boolean eaccelerator_unlock (string $key)
下面有部分網(wǎng)友翻譯后的接口說(shuō)明:
eaccelerator_put($key, $value, $ttl=0)
將 $value 以 $key 為鍵名存進(jìn)緩存(php4下支持對(duì)像類(lèi)型,看源碼好像zend2里不支持了),$ttl 是這個(gè)緩存的生命周期,單位是秒,省略該參數(shù)或指定為 0 表示不限時(shí),直到服務(wù)器重啟清空為止。
eaccelerator_get($key)
根據(jù) $key 從緩存中返回相應(yīng)的 eaccelerator_put() 存進(jìn)去的數(shù)據(jù),如果這項(xiàng)緩存已經(jīng)過(guò)期或不存在那么返回值是 NULL
eaccelerator_rm($key)
根據(jù) $key 移除緩存
eaccelerator_gc()
移除清理所有已過(guò)期的 key
eaccelerator_lock($key)
為 $key 加上鎖定操作,以保證多進(jìn)程多線(xià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));
?>
eaccelerator_unlock($key)
根據(jù) $key 釋放鎖
eaccelerator_cache_output($key, $eval_code, $ttl=0)
將 $eval_code 代碼的輸出緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put)
例如:
<?php eaccelerator_cache_output(‘test', ‘echo time(); phpinfo();', 30); ?>
eaccelerator_cache_result($key, $eval_code, $ttl=0)
將 $eval_code 代碼的執(zhí)行結(jié)果緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put),類(lèi)似 cache_output
例如:
<?php eaccelerator_cache_result(‘test', ‘ time() . “Hello”;', 30); ?>
eaccelerator_cache_page($key, $ttl=0)
將當(dāng)前整頁(yè)緩存 $ttl 秒。
例如:
<?php
eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
echo time();
phpinfo();
?>
eaccelerator_rm_page($key)
刪除由 eaccelerator_cache_page() 執(zhí)行的緩存,參數(shù)也是 $key
2、PHP代碼中使用eAccelerator加速
另外,在PHPCMS里面已經(jīng)集成了對(duì)eAccelerator的支持,下面是一段來(lái)自PHPCMS里面的代碼
class cache
{
function __construct()
{
}
function cache()
{
$this->__construct();
}
function get($name)
{
return eaccelerator_get($name);
}
function set($name, $value, $ttl = 0)
{
eaccelerator_lock($name);
return eaccelerator_put($name, $value, $ttl);
}
function rm($name)
{
return eaccelerator_rm($name);
}
function clear()
{
return eaccelerator_gc();
}
}
eAccelerator提供了便捷便捷而又穩(wěn)定的本機(jī)緩存實(shí)現(xiàn)方式,由于大部分代碼實(shí)現(xiàn)基于共享內(nèi)存,所以只能在*nix平臺(tái)中使用,Windows平臺(tái)Michael就暫時(shí)不知道何時(shí)有這方面的支持了。
eAccelerator提供如下的API接口和文件:(下述文件均在源碼包的doc/php/目錄下)
文件列表:
復(fù)制代碼 代碼如下:
cache.php
dasm.php
encoder.php
info.php
loader.php
session.php
shared_memory.php
接口列表:
復(fù)制代碼 代碼如下:
array eaccelerator_cached_scripts ()
void eaccelerator_cache_output (string $key, string $eval_code, [int $ttl = 0])
void eaccelerator_cache_page (string $key, [int $ttl = 0])
void eaccelerator_cache_result (string $key, string $code, [int $ttl = 0])
void eaccelerator_caching (boolean $flag)
void eaccelerator_clean ()
void eaccelerator_clear ()
array eaccelerator_dasm_file (mixed $filename)
mixed eaccelerator_encode (mixed $src, [mixed $prefix = ''], [string $pre_content = ''], [string $post_content = ''])
void eaccelerator_gc ()
mixed eaccelerator_get (string $key)
array eaccelerator_info ()
array eaccelerator_list_keys ()
void eaccelerator_load ()
boolean eaccelerator_lock (string $key)
void eaccelerator_optimizer (boolean $flag)
void eaccelerator_purge ()
boolean eaccelerator_put (string $key, mixed $value, [int $ttl = 0])
array eaccelerator_removed_scripts ()
boolean eaccelerator_rm (string $key)
void eaccelerator_rm_page (string $key)
boolean eaccelerator_set_session_handlers ()
boolean eaccelerator_unlock (string $key)
下面有部分網(wǎng)友翻譯后的接口說(shuō)明:
復(fù)制代碼 代碼如下:
eaccelerator_put($key, $value, $ttl=0)
將 $value 以 $key 為鍵名存進(jìn)緩存(php4下支持對(duì)像類(lèi)型,看源碼好像zend2里不支持了),$ttl 是這個(gè)緩存的生命周期,單位是秒,省略該參數(shù)或指定為 0 表示不限時(shí),直到服務(wù)器重啟清空為止。
eaccelerator_get($key)
根據(jù) $key 從緩存中返回相應(yīng)的 eaccelerator_put() 存進(jìn)去的數(shù)據(jù),如果這項(xiàng)緩存已經(jīng)過(guò)期或不存在那么返回值是 NULL
eaccelerator_rm($key)
根據(jù) $key 移除緩存
eaccelerator_gc()
移除清理所有已過(guò)期的 key
eaccelerator_lock($key)
為 $key 加上鎖定操作,以保證多進(jìn)程多線(xià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));
?>
eaccelerator_unlock($key)
根據(jù) $key 釋放鎖
eaccelerator_cache_output($key, $eval_code, $ttl=0)
將 $eval_code 代碼的輸出緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put)
例如:
<?php eaccelerator_cache_output(‘test', ‘echo time(); phpinfo();', 30); ?>
eaccelerator_cache_result($key, $eval_code, $ttl=0)
將 $eval_code 代碼的執(zhí)行結(jié)果緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put),類(lèi)似 cache_output
例如:
<?php eaccelerator_cache_result(‘test', ‘ time() . “Hello”;', 30); ?>
eaccelerator_cache_page($key, $ttl=0)
將當(dāng)前整頁(yè)緩存 $ttl 秒。
例如:
<?php
eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
echo time();
phpinfo();
?>
eaccelerator_rm_page($key)
刪除由 eaccelerator_cache_page() 執(zhí)行的緩存,參數(shù)也是 $key
2、PHP代碼中使用eAccelerator加速
另外,在PHPCMS里面已經(jīng)集成了對(duì)eAccelerator的支持,下面是一段來(lái)自PHPCMS里面的代碼
復(fù)制代碼 代碼如下:
class cache
{
function __construct()
{
}
function cache()
{
$this->__construct();
}
function get($name)
{
return eaccelerator_get($name);
}
function set($name, $value, $ttl = 0)
{
eaccelerator_lock($name);
return eaccelerator_put($name, $value, $ttl);
}
function rm($name)
{
return eaccelerator_rm($name);
}
function clear()
{
return eaccelerator_gc();
}
}
您可能感興趣的文章:
- PHP開(kāi)發(fā)api接口安全驗(yàn)證的實(shí)例講解
- PHP服務(wù)器端API原理及示例講解(接口開(kāi)發(fā))
- 支付寶服務(wù)窗API接口開(kāi)發(fā)php版本
- 淺談使用 PHP 進(jìn)行手機(jī) APP 開(kāi)發(fā)(API 接口開(kāi)發(fā))
- eaglephp使用微信api接口開(kāi)發(fā)微信框架
- 新浪微博API開(kāi)發(fā)簡(jiǎn)介之用戶(hù)授權(quán)(PHP基礎(chǔ)篇)
- 利用Yahoo! Search API開(kāi)發(fā)自已的搜索引擎-php版
- php版微信小店API二次開(kāi)發(fā)及使用示例
- Thinkphp 在api開(kāi)發(fā)中異常返回依然是html的解決方式
- PHP開(kāi)發(fā)api接口安全驗(yàn)證操作實(shí)例詳解
相關(guān)文章
PHP封裝的XML簡(jiǎn)單操作類(lèi)完整實(shí)例
這篇文章主要介紹了PHP封裝的XML簡(jiǎn)單操作類(lèi),結(jié)合完整實(shí)例形式分析了php針對(duì)xml文件進(jìn)行載入、讀取及寫(xiě)入相關(guān)操作技巧的封裝與使用方法,需要的朋友可以參考下2017-11-11基于php+redis實(shí)現(xiàn)布隆過(guò)濾器
布隆過(guò)濾器(Bloom filter)是一種用于快速判斷一個(gè)元素是否存在于集合中的數(shù)據(jù)結(jié)構(gòu),它可以有效地檢索數(shù)據(jù),而不需要存儲(chǔ)實(shí)際的元素本身,本文給大家介紹了如何基于php+redis實(shí)現(xiàn)布隆過(guò)濾器,感興趣的朋友可以參考下2023-12-12php實(shí)現(xiàn)的Curl封裝類(lèi)Curl.class.php用法實(shí)例分析
這篇文章主要介紹了php實(shí)現(xiàn)的Curl封裝類(lèi)Curl.class.php用法,以完整實(shí)例形式較為詳細(xì)的分析了Curl封裝類(lèi)的定義及相關(guān)使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09PHP實(shí)現(xiàn)取得HTTP請(qǐng)求的原文
這篇文章主要介紹了PHP實(shí)現(xiàn)取得HTTP請(qǐng)求的原文,需要的朋友可以參考下2014-08-08