How to use Eaccelerator to speed up PHP code _php instance

Source: Internet
Author: User
Tags php source code phpinfo
Eaccelerator is really a good thing (its predecessor is Truck-mmcache).

In short, it is a set of PHP (support PHP5) operation of the caching system, through the sharing of memory or disk files to Exchange data.

It is widely used in PHP source code "code" (not too aptly known as "Encryption") and cache php execution of the middle code to accelerate. There have been a lot of articles about the installation of EA and it's also very detailed, and this time I would recommend using it to assist in programming caching, which provides a set of APIs as follows:

is a very convenient and stable native cache implementation, the current part of the design seems to support only shared memory, so only for the Unix-like OS, Windows is not this blessing.

1. Eaccelerator_put ($key, $value, $ttl =0)
The $value is stored in the $key as a key to the cache (PHP4 support for the image type, look at the source as if Zend2 does not support), $ttl is the life cycle of this cache, the unit is seconds, omit this parameter or specify 0 for unlimited time until the server restart empty.

2. Eaccelerator_get ($key)
The return value is NULL if the cache has expired or does not exist, depending on $key the data that is stored in the corresponding eaccelerator_put () from the cache.

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

4. EACCELERATOR_GC ()
Remove clean all expired key

5. Eaccelerator_lock ($key)
A locking operation is added to the $key to ensure the synchronization of the data during multiple-process multithreaded operations. You need to call Eaccelerator_unlock ($key) to release the lock or wait for the end of the program request to automatically release the lock.
For example:
<?php
Eaccelerator_lock ("Count");
Eaccelerator_put ("Count", Eaccelerator_get ("Count") +1);
?>

6. Eaccelerator_unlock ($key)
Releasing locks according to $key

7. Eaccelerator_cache_output ($key, $eval _code, $ttl =0)
The output of the $eval _code code is cached $ttl seconds ($ttl parameter is the same as Eacclerator_put)
For Example:
<?php eaccelerator_cache_output (' Test ', ' echo Time '); Phpinfo ();?>

8. Eaccelerator_cache_result ($key, $eval _code, $ttl =0)
The execution result of the $eval _code code is cached $ttl seconds ($ttl parameters are the same as Eacclerator_put), similar to the Cache_output
For Example:
<?php eaccelerator_cache_result (' Test ', ' time ' (). "Hello"; "?>";

9. Eaccelerator_cache_page ($key, $ttl =0)
$ttl seconds to cache the current full-page page.
For Example:
<?php
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 (), which is also the parameter $key

______________________________________________
(For a simple example, look at its power, note that it may not work in CLI mode!) )


<?phpclass test_cache {  var  $pro  =  ' Hello ';  function  Test_cache ()  {    echo  "object created!<br>/n";  }   function func ()  {    echo  ',  the world! ';   }  function now ($t)  {    echo date (' Y-m-d H:i:s ') ,  $t);  &nbsp}} $tt  = eaccelerator_get ("Test_tt");if  (! $tt) {   $tt  =  new test_cache;  eaccelerator_put ("Test_tt",  $tt);  echo  "no  Cached!<br>/n ";} else {  echo  "cached<br>/n";} echo  $tt->pro;  $tt->func (); $tt->now (Time ()  + 86400); >

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.