Use Eaccelerator to speed up the purpose of PHP code _php tips

Source: Internet
Author: User
Tags echo date eval php source code phpinfo
Using Eaccelerator to speed up PHP code
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!) )
<?php
Class 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);
}
}
$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);
?>
The following is a Netizen's comments:
--------------------------------------------------------------------------------
SHOWSA reply in: 2005-12-31 19:51:56win also support! http://www.arnot.info/eaccelerator/
Albatross back: 2006-01-04 17:17:37 The latest version of Eaccelerator 0.9.4-rc1 has a small bug showing a large number of/var/log/httpd/error_log (warn) broken PIPE:WR  ITE Pipe_of_death Error Message resolution Modify DEBUG.C file-----------------------------------------------/** * Close the debug system.     * * void Ea_debug_shutdown () {fflush (F_FP);    SOURCE statement, when the file is closed, there is no detection file handle//fclose (F_FP);      Change to if (f_fp!= stderr) fclose (F_FP); F_FP = NULL; }
Soichiro back to: 2006-01-10 22:01:21eaccelerator/truck-mmcache is horrible, I now have two highly loaded systems, one based on Drupal, the other based on PostNuke, After using the eaccelerator, drual speed 100 times times, PostNuke Ascension 10 times times, PostNuke Ascension is relatively small because it itself is very fast.
Wangyih back to: 2006-04-08 10:48:11 and the use of squid than how
SHOWSA reply to: 2006-04-08 23:23:44 how to go and squid to go than ah different things squid is cached page run results if not real-time display, squid must be strong but the forum and so on, squid is not, with eaccelerator/ Memcache can improve efficiency to a large extent
Yarco back to: 2006-04-09 10:00:43 But it's said to be in conflict with encode code ... Do not know what is the compatibility of current and Zend?
Related Article

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.