欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

探討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/目錄下)
文件列表:
復(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();
    }
}

相關(guān)文章

  • 上傳文件先創(chuàng)建目錄 再上傳到目錄里面去

    上傳文件先創(chuàng)建目錄 再上傳到目錄里面去

    上傳文件先創(chuàng)建目錄,其實(shí)應(yīng)該先加入判斷文件夾是否存在,不存在則創(chuàng)建文件夾的,希望朋友們自行添加,這里給出的是核心代碼。
    2010-12-12
  • PHP封裝的XML簡(jiǎn)單操作類(lèi)完整實(shí)例

    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ò)濾器

    基于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-12
  • 11個(gè)PHPer必須要了解的編程規(guī)范

    11個(gè)PHPer必須要了解的編程規(guī)范

    從設(shè)計(jì)之初,PHP被廣泛用于開(kāi)發(fā)基于Web的應(yīng)用程序。 由于PHP是一種腳本語(yǔ)言,開(kāi)發(fā)的時(shí)候必須遵守一些規(guī)范。
    2014-09-09
  • Linux php 中文亂碼的快速解決方法

    Linux php 中文亂碼的快速解決方法

    下面小編就為大家?guī)?lái)一篇Linux php 中文亂碼的快速解決方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧
    2016-05-05
  • PHP中的錯(cuò)誤及其處理機(jī)制

    PHP中的錯(cuò)誤及其處理機(jī)制

    這篇文章主要介紹了PHP中錯(cuò)誤和異常的概念,幫助大家更好的理解和學(xué)習(xí)使用PHP,感興趣的朋友可以了解下
    2021-04-04
  • php實(shí)現(xiàn)的Curl封裝類(lèi)Curl.class.php用法實(shí)例分析

    php實(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-09
  • php使用COPY函數(shù)更新配置文件的方法

    php使用COPY函數(shù)更新配置文件的方法

    這篇文章主要介紹了php使用COPY函數(shù)更新配置文件的方法,涉及copy函數(shù)更新配置信息的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • PHP實(shí)現(xiàn)取得HTTP請(qǐng)求的原文

    PHP實(shí)現(xiàn)取得HTTP請(qǐng)求的原文

    這篇文章主要介紹了PHP實(shí)現(xiàn)取得HTTP請(qǐng)求的原文,需要的朋友可以參考下
    2014-08-08
  • php類(lèi)的定義與繼承用法實(shí)例

    php類(lèi)的定義與繼承用法實(shí)例

    這篇文章主要介紹了php類(lèi)的定義與繼承用法,實(shí)例分析了php中類(lèi)的基本定義與繼承的使用技巧,需要的朋友可以參考下
    2015-07-07

最新評(píng)論