Discuss the detailed explanation of API development using eAccelerator in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:07:34
Original
979 people have browsed it

1. API and documentation description:
eAccelerator provides a convenient and stable native cache implementation. Since most of the code implementation is based on shared memory, it can only be implemented in *nix platform is used, and Windows platform Michael does not know when this support will be available.
eAccelerator provides the following API interfaces and files: (The following files are in the doc/php/ directory of the source code package)
File list:

Copy code The code is as follows:

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

Interface list:
Copy code The code is as follows:

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)

Here are the interface descriptions translated by some netizens:
Copy the code The code is as follows:

eaccelerator_put($key, $value, $ttl=0)
Save $value into the cache with $key as the key name (object type is supported under php4, but looking at the source code, it seems that it is not supported in zend2 ), $ttl is the life cycle of this cache, in seconds. Omitting this parameter or specifying it as 0 means there is no time limit until the server is restarted and cleared.

eaccelerator_get($key)
Returns the data stored in the corresponding eaccelerator_put() from the cache according to $key. If the cache has expired or does not exist, the return value is NULL

eaccelerator_rm($key)
Remove cache according to $key

eaccelerator_gc()
Remove and clean up all expired keys

eaccelerator_lock($key)
as $key plus locking operation to ensure data synchronization during multi-process and multi-thread operations. You need to call eaccelerator_unlock($key) to release this lock or wait for the program request to automatically release this lock.
For example:
eaccelerator_lock(“count”);
eaccelerator_put(“count”,eaccelerator_get(“count”)+1));
?>

eaccelerator_unlock($key)
Release the lock based on $key

eaccelerator_cache_output($key, $eval_code, $ttl=0)
Cache the output of the $eval_code code for $ttl seconds, ($ttl parameter is the same as eacclerator_put)
For example:


eaccelerator_cache_result ($key, $eval_code, $ttl=0)
Cache the execution result of the $eval_code code for $ttl seconds, ($ttl parameter is the same as eacclerator_put), similar to cache_output
For example:


eaccelerator_cache_page($key, $ttl=0)
Cache the current entire page for $ttl seconds.
For example:
eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
echo time();
phpinfo();
?>

eaccelerator_rm_page($key)
Delete the cache executed by eaccelerator_cache_page(), the parameter is also $key

2. Use eAccelerator to accelerate PHP code
In addition, support for eAccelerator has been integrated in PHPCMS. The following is a piece of code from PHPCMS
Copy code The code is as follows:

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();
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327534.htmlTechArticle1. API and documentation description: eAccelerator provides a convenient, convenient and stable native cache implementation method. Part of the code implementation is based on shared memory, so it can only be used on *nix platforms...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template