Explore PHP's API development _php tutorials using Eaccelerator

Source: Internet
Author: User
1. API and Documentation Description:
Eaccelerator provides a convenient and stable native cache implementation, because most code implementations are based on shared memory and can only be used in the *nix platform, and the Windows platform Michael does not know when this is supported.
Eaccelerator provides the following API interface and files: (The following files are in the source package doc/php/directory)
file list:
Copy CodeThe code is as follows:
cache.php
dasm.php
encoder.php
info.php
loader.php
session.php
shared_memory.php

Interface list:
Copy CodeThe 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 some of the user interface after the translation of the description:
Copy CodeThe code is as follows:
Eaccelerator_put ($key, $value, $ttl =0)
The $value to the $key as the key name in the cache (PHP4 support for the type of image, see the source is not supported in the Zend2), $ttl is the life cycle of this cache, the unit is the second, omit the parameter or specify 0 for unlimited, until the server restarts to empty.

Eaccelerator_get ($key)
The return value is NULL if the cache has expired or is not present, based on $key returning the corresponding eaccelerator_put () data from the cache.

EACCELERATOR_RM ($key)
To remove a cache from a $key

EACCELERATOR_GC ()
Remove cleanup of all expired keys

Eaccelerator_lock ($key)
For $key plus locking operations to ensure data synchronization during multi-process multithreaded operations. You need to call Eaccelerator_unlock ($key) to release this lock or to automatically release this lock when the program request ends.
For example:
Eaccelerator_lock ("Count");
Eaccelerator_put ("Count", Eaccelerator_get ("Count") +1));
?>

Eaccelerator_unlock ($key)
Release the lock according to the $key

Eaccelerator_cache_output ($key, $eval _code, $ttl =0)
$eval the output cache of the _code code $ttl seconds ($ttl parameter same as Eacclerator_put)
For example:


Eaccelerator_cache_result ($key, $eval _code, $ttl =0)
Caches the execution results of the $eval _code code $ttl seconds ($ttl parameter with eacclerator_put), similar to Cache_output
For example:


Eaccelerator_cache_page ($key, $ttl =0)
Caches the current full page $ttl seconds.
For example:
Eaccelerator_cache_page ($_server[' php_self '). Get= '. Serialize ($_get), 30);
echo Time ();
Phpinfo ();
?>

Eaccelerator_rm_page ($key)
Deletes the cache executed by Eaccelerator_cache_page (), and the parameters are also $key

2. Use eaccelerator acceleration in PHP code
In addition, the support for Eaccelerator has been integrated into the PHPCMS, and the following is a code from PHPCMS
Copy CodeThe 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 ();
}
}

http://www.bkjia.com/PHPjc/327534.html www.bkjia.com true http://www.bkjia.com/PHPjc/327534.html techarticle 1, API and Documentation Description: Eaccelerator provides a convenient and stable native cache implementation, because most of the code implementation is based on shared memory, so it can only be used in the *nix platform ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.