Home >Backend Development >PHP Tutorial >Detailed explanation of eAccelerator API development in PHP

Detailed explanation of eAccelerator API development in PHP

WBOY
WBOYOriginal
2016-07-25 08:53:18841browse
  1. eaccelerator_lock(“count”);
  2. eaccelerator_put(“count”,eaccelerator_get(“count”)+1));
  3. ?>
Copy code

eaccelerator_unlock($ key) Release lock based on $key

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

Copy code

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

Copy code

eaccelerator_cache_page($key, $ttl=0 ) Cache the current full page for $ttl seconds. For example:

  1. eaccelerator_cache_page($_SERVER['PHP_SELF'].'?GET='.serialize($_GET),30);
  2. echo time();
  3. phpinfo();
  4. ?> ;
Copy code

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, PHPCMS has integrated support for eAccelerator. The following is a piece of code from PHPCMS.

  1. class cache

  2. {
  3. function __construct()
  4. {
  5. }

  6. function cache()

  7. {
  8. $this->__construct();
  9. }

  10. function get($name)

  11. {
  12. return eaccelerator_get($name);
  13. }

  14. function set($name, $value, $ ttl = 0)

  15. {
  16. eaccelerator_lock($name);
  17. return eaccelerator_put($name, $value, $ttl);
  18. }

  19. function rm($name)

  20. {
  21. return eaccelerator_rm ($name);
  22. }

  23. function clear()

  24. {
  25. return eaccelerator_gc();
  26. }
  27. }

Copy code


Statement:
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