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

探討PHP使用eAccelerator的API開發(fā)詳解

 更新時間:2013年06月09日 11:14:03   作者:  
本篇文章是對PHP使用eAccelerator的API開發(fā)進行了詳細的分析介紹,需要的朋友參考下
1、API和文檔說明:
eAccelerator提供了便捷便捷而又穩(wěn)定的本機緩存實現(xiàn)方式,由于大部分代碼實現(xiàn)基于共享內(nèi)存,所以只能在*nix平臺中使用,Windows平臺Michael就暫時不知道何時有這方面的支持了。
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)友翻譯后的接口說明:
復制代碼 代碼如下:

eaccelerator_put($key, $value, $ttl=0)
  將 $value 以 $key 為鍵名存進緩存(php4下支持對像類型,看源碼好像zend2里不支持了),$ttl 是這個緩存的生命周期,單位是秒,省略該參數(shù)或指定為 0 表示不限時,直到服務器重啟清空為止。

eaccelerator_get($key)
  根據(jù) $key 從緩存中返回相應的 eaccelerator_put() 存進去的數(shù)據(jù),如果這項緩存已經(jīng)過期或不存在那么返回值是 NULL

eaccelerator_rm($key)
  根據(jù) $key 移除緩存

eaccelerator_gc()
  移除清理所有已過期的 key

eaccelerator_lock($key)
  為 $key 加上鎖定操作,以保證多進程多線程操作時數(shù)據(jù)的同步。需要調(diào)用 eaccelerator_unlock($key) 來釋放這個鎖或等待程序請求結束時自動釋放這個鎖。
  例如:
  <?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í)行結果緩存 $ttl 秒,($ttl參數(shù)同 eacclerator_put),類似 cache_output
  例如:
  <?php eaccelerator_cache_result(‘test', ‘ time() . “Hello”;', 30); ?>

eaccelerator_cache_page($key, $ttl=0)
  將當前整頁緩存 $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)集成了對eAccelerator的支持,下面是一段來自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();
    }
}

相關文章

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

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

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

    PHP封裝的XML簡單操作類完整實例

    這篇文章主要介紹了PHP封裝的XML簡單操作類,結合完整實例形式分析了php針對xml文件進行載入、讀取及寫入相關操作技巧的封裝與使用方法,需要的朋友可以參考下
    2017-11-11
  • 基于php+redis實現(xiàn)布隆過濾器

    基于php+redis實現(xiàn)布隆過濾器

    布隆過濾器(Bloom filter)是一種用于快速判斷一個元素是否存在于集合中的數(shù)據(jù)結構,它可以有效地檢索數(shù)據(jù),而不需要存儲實際的元素本身,本文給大家介紹了如何基于php+redis實現(xiàn)布隆過濾器,感興趣的朋友可以參考下
    2023-12-12
  • 11個PHPer必須要了解的編程規(guī)范

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

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

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

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

    PHP中的錯誤及其處理機制

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

    php實現(xiàn)的Curl封裝類Curl.class.php用法實例分析

    這篇文章主要介紹了php實現(xiàn)的Curl封裝類Curl.class.php用法,以完整實例形式較為詳細的分析了Curl封裝類的定義及相關使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • php使用COPY函數(shù)更新配置文件的方法

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

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

    PHP實現(xiàn)取得HTTP請求的原文

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

    php類的定義與繼承用法實例

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

最新評論