Rumah  >  Artikel  >  pembangunan bahagian belakang  >  PHP加速器eAccelerator配置使用指南

PHP加速器eAccelerator配置使用指南

WBOY
WBOYasal
2016-07-25 08:53:16859semak imbas
  1. #tar -zxvf ./eaccelerator-0.9.5-beta2.tar.bz2
  2. #cd eaccelerator-0.9.5-beta2
  3. #export PHP_PREFIX="/usr/local" (把PHP安装目录导入到环境变量,FreeBSD默认是/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
复制代码

4、ini文件配置 安装完成,下面开始配置php.ini文件,eAccelerator提供了两种配置和调用方式,分别如下。 安装为 Zend extension 模式:

  1. #mkdir /tmp/eaccelerator
  2. #chmod 777 /tmp/eaccelerator
复制代码

5、验证安装结果 通过浏览器访问您的phpinfo()页面或者运行 php -i 得到php配置信息,里面如果看到类似下面的信息就表示安装成功了。 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,所以看到的信息如下: 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 如果你打开了eAccelerator的debug选项,可以从日志中看到类似下面的信息

  1. eaccelerator_lock("count");
  2. eaccelerator_put("count",eaccelerator_get("count")+1));
  3. ?>
复制代码

eaccelerator_unlock($key) 根据 $key 释放锁

eaccelerator_cache_output($key, $eval_code, $ttl=0) 将 $eval_code 代码的输出缓存 $ttl 秒,($ttl参数同 eacclerator_put) 例如:

复制代码

eaccelerator_cache_result($key, $eval_code, $ttl=0) 将 $eval_code 代码的执行结果缓存 $ttl 秒,($ttl参数同 eacclerator_put),类似 cache_output 例如:

复制代码

eaccelerator_cache_page($key, $ttl=0) 将当前整页缓存 $ttl 秒。 例如:

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

eaccelerator_rm_page($key) 删除由 eaccelerator_cache_page() 执行的缓存,参数也是 $key

2、php代码中使用eAccelerator加速 测试下eAccelerator强大的威力:(该代码在 cli 模式下可能无效)

  1. class test_cache {

  2. var $pro = 'hello';
  3. function test_cache() {

  4. echo "Object Created!
    \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. ?>
复制代码

另外,据说在著名的vBulletin 3.60Beta版里面已经集成了对eAccelerator的支持。 一段来自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. }
复制代码


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn