Discuss PHP using eAccelerator API development details

  • 2020-06-12 08:36:03
  • OfStack

1. API and Documentation:
eAccelerator provides a convenient and stable implementation of native caching, and since most of the code implementation is based on Shared memory, it is only available for the *nix platform. It is not known when the Windows platform will have this support.
eAccelerator provides the following API interface and files :(the following files are under the doc/php/ directory of the source package)
List of documents:

    cache.php
    dasm.php
    encoder.php
    info.php
    loader.php
    session.php
    shared_memory.php

Interface list:

    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)

The following is a partial netizen translation after the interface description:

eaccelerator_put($key, $value, $ttl=0)
   will  $value  In order to  $key  Store the key name in the cache (php4 Under support for like type, look at the source like zend2 No longer ) . $ttl  Is the lifetime of the cache in seconds, omitted or specified as  0  Indicates unlimited time until the server is restarted and cleared. 

eaccelerator_get($key)
   According to the  $key  Returns the corresponding from the cache  eaccelerator_put()  If the cache has expired or does not exist then the return value is  NULL

eaccelerator_rm($key)
   According to the  $key  Remove the cache 

eaccelerator_gc()
   Remove and clean up all expired ones  key

eaccelerator_lock($key)
   for  $key  Locking operations are added to ensure synchronization of data during multi-process and multi-threaded operations. You need to call  eaccelerator_unlock($key)  To release the lock or to automatically release the lock when the program request ends. 
   For example, :
  <?php
    eaccelerator_lock( " count " );
    eaccelerator_put( " count " ,eaccelerator_get( " count " )+1));
  ?>

eaccelerator_unlock($key)
   According to the  $key  Release the lock 

eaccelerator_cache_output($key, $eval_code, $ttl=0)
   will  $eval_code  Output cache for code  $ttl  Second, ( $ttl Parameters with  eacclerator_put ) 
   Such as: 
  <?php eaccelerator_cache_output( ' test',  ' echo time(); phpinfo();', 30); ?>

eaccelerator_cache_result($key, $eval_code, $ttl=0)
   will  $eval_code  Cache the execution results of the code  $ttl  Second, ( $ttl Parameters with  eacclerator_put ), similar to  cache_output
   Such as: 
  <?php eaccelerator_cache_result( ' test',  '  time() .  " Hello " ;', 30); ?>

eaccelerator_cache_page($key, $ttl=0)
   Caches the current full page  $ttl  Seconds. 
   Such as: 
  <?php
    eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
    echo time();
    phpinfo();
  ?>

eaccelerator_rm_page($key)
   Delete the   eaccelerator_cache_page()  Executes the cache, and so does the argument  $key

2. eAccelerator acceleration is used in PHP code
In addition, PHPCMS has integrated support for eAccelerator. Here is a snippet of code from 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();
    }
}


Related articles: