Home  >  Article  >  Backend Development  >  PHP accelerator eAccelerator configuration and usage guide

PHP accelerator eAccelerator configuration and usage guide

WBOY
WBOYOriginal
2016-07-25 08:53:16897browse
  1. #tar -zxvf ./eaccelerator-0.9.5-beta2.tar.bz2
  2. #cd eaccelerator-0.9.5-beta2
  3. #export PHP_PREFIX="/usr/local" (Import the PHP installation directory to Environment variables, FreeBSD defaults to /usr/local)
  4. #$PHP_PREFIX/bin/phpize
  5. #./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
  6. #make
  7. #make install
Copy code

4. ini file configuration After the installation is complete, let's start configuring the php.ini file. eAccelerator provides two configuration and calling methods, as follows. Install in Zend extension mode:

  1. #mkdir /tmp/eaccelerator
  2. #chmod 777 /tmp/eaccelerator
Copy the code

5. Verify the installation results Access your phpinfo() page through a browser or run php -i to get the PHP configuration information. If you see information similar to the following, the installation is successful. This program makes use of the Zend Scripting Language Engine: Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies with eAccelerator v0.9.5-beta2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator Zend Optimizer3.0.1 is also installed on my machine, so the information I see is as follows: This program makes use of the Zend Scripting Language Engine: Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies with eAccelerator v0.9.5-beta2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator with Zend Extension Manager v1.0.10, Copyright (c) 2003-2006, by Zend Technologies with Zend Optimizer v3.0.1, Copyright (c) 1998-2006, by Zend Technologies If you turn on the debug option of eAccelerator, you can see information similar to the following in the log

  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 Test the powerful power of eAccelerator: (This code may not be valid in cli mode)

  1. class test_cache {

  2. var $pro = 'hello';

  3. function test_cache() {

  4. echo "Object Created!< ;br>n";
  5. }
  6. function func() {
  7. echo ', the world!';
  8. }
  9. function now($t) {
  10. echo date('Y-m-d H:i:s', $t);
  11. }
  12. }

  13. $tt = eaccelerator_get("test_tt");

  14. if (!$tt)
  15. {
  16. $tt = new test_cache;
  17. eaccelerator_put("test_tt", $tt) ;
  18. echo "no cached!
    n";
  19. }
  20. else {
  21. echo "cached
    n";
  22. }

  23. echo $tt->pro;

  24. $tt->func();
  25. $tt->now(time() + 86400);
  26. ?>
Copy code

In addition, it is said that support for eAccelerator has been integrated into the famous vBulletin 3.60Beta version. A piece of code from vBulletin

  1. // #############

  2. // eAccelerator

  3. /**

  4. * Class for fetching and initializing the vBulletin datastore from eAccelerator
  5. *
  6. * @package vBulletin
  7. * @version $Revision: 0.1 $
  8. * @date $Date: 2005/06/12 13:14:18 $
  9. */
  10. class vB_Datastore_eAccelerator extends vB_Datastore
  11. {
  12. /**
  13. * Fetches the contents of the datastore from eAccelerator
  14. *
  15. * @param array Array of items to fetch from the datastore
  16. *
  17. * @return void
  18. */
  19. function fetch($itemarray)
  20. {
  21. if (!function_exists('eaccelerator_get'))
  22. {
  23. trigger_error("eAccelerator not installed", E_USER_ERROR);
  24. }

  25. foreach ($this->defaultitems AS $item)

  26. {
  27. $this->do_fetch($item);
  28. }

  29. if ( is_array($itemarray))

  30. {
  31. foreach ($itemarray AS $item)
  32. {
  33. $this->do_fetch($item);
  34. }
  35. }

  36. $this-> check_options();

  37. // set the version number variable

  38. $this->registry->versionnumber =& $this->registry->options['templateversion'];
  39. }

  40. /**

  41. * Fetches the data from shared memory and detects errors
  42. *
  43. * @param string title of the datastore item
  44. *
  45. * @return void
  46. */
  47. function do_fetch($title)
  48. {
  49. $data = eaccelerator_get($title);
  50. if ($data === null)
  51. { // appears its not there, lets grab the data, lock the shared memory and put it in
  52. $data = '';
  53. $dataitem = $this->dbobject->query_first("
  54. SELECT title, data FROM " . TABLE_PREFIX . "datastore
  55. WHERE title = '" . $this->dbobject->escape_string($title) ."'
  56. ");
  57. if (!empty($dataitem['title']))
  58. {
  59. $data =& $dataitem['data'];
  60. $this->build($dataitem['title'], $dataitem['data']);
  61. }
  62. }
  63. $this->register ($title, $data);
  64. }
  65. /**
  66. * Updates the appropriate cache file
  67. *
  68. * @param string title of the datastore item
  69. *
  70. * @return void
  71. */
  72. function build($title, $data)
  73. {
  74. if (!function_exists('eaccelerator_put'))
  75. {
  76. trigger_error("eAccelerator not installed", E_USER_ERROR);
  77. }
  78. eaccelerator_lock($title);
  79. eaccelerator_put($title, $data);
  80. eaccelerator_unlock($title);
  81. }
  82. }

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