EcStart PHP 技術討論論壇's Archiver

FIEND 發表於 2003-12-19 22:01

Turck MMCache for PHP

Turck MMCache 具有快取和編譯的弁� ...

官方文件

[url=http://turck-mmcache.sourceforge.net/index_old.html]http://turck-mmcache.sourceforge.net/index_old.html[/url]

使用方法

Step 1. Compiling Turck MMCache

  export PHP_PREFIX="/usr"
  $PHP_PREFIX/bin/phpize
  ./configure --enable-mmcache=shared --with-php-config=$PHP_PREFIX/bin/php-config
  make

You must specify the real prefix where PHP is installed in the "export" command. It may be "/usr" "/usr/local", or something else.

Step 2. Installing Turck MMCache

  make install

Step 3. Configuring Turck MMCache
Turck MMCache can be installed both as Zend or PHP extension, so you need to edit your php.ini file (usually /etc/php.ini).
To install as Zend extension:

  zend_extension="/usr/lib/php4/mmcache.so"
  mmcache.shm_size="16"
  mmcache.cache_dir="/tmp/mmcache"
  mmcache.enable="1"
  mmcache.optimizer="1"
  mmcache.check_mtime="1"
  mmcache.debug="0"
  mmcache.filter=""
  mmcache.shm_max="0"
  mmcache.shm_ttl="0"
  mmcache.shm_prune_period="0"
  mmcache.shm_only="0"
  mmcache.compress="1"

If you use thread safe build of PHP you must use "zend_extension_ts" instead of "zend_extension".

To install as PHP extension:

  extension="mmcache.so"
  mmcache.shm_size="16"
  mmcache.cache_dir="/tmp/mmcache"
  mmcache.enable="1"
  mmcache.optimizer="1"
  mmcache.check_mtime="1"
  mmcache.debug="0"
  mmcache.filter=""
  mmcache.shm_max="0"
  mmcache.shm_ttl="0"
  mmcache.shm_prune_period="0"
  mmcache.shm_only="0"
  mmcache.compress="1"

Step 4. Creating cache directory

  mkdir /tmp/mmcache
  chmod 0777 /tmp/mmcache

Windows Installation Notes

To build Turck MMCache on Windows platform you will need MS Visual Studio C++ 6.0.

Step 1. Compiling Turck MMCache
- Unpack php sources.
- Put mmcache sources under "ext/mmcache".
- Put "php4ts.lib" into "ext/mmcache".
- Copy "main/config.w32.h.in" into "main/config.w32.h".
- Open project file "ext/mmcache/mmcache.dsp".
- Select release configuration and build "mmcache.dll".

Step 2. Installing Turck MMCache
Copy "mmcache.dll" into your PHP extension folder.

Step 3. Configuring Turck MMCache
Add the following lines into your "php.ini" file (usually "c:winntphp.ini")

  zend_extension_ts="c:fullpathtommcachemmcache.dll"
  mmcache.shm_size="16"
  mmcache.cache_dir="c:tmpmmcache"
  mmcache.enable="1"
  mmcache.optimizer="1"
  mmcache.check_mtime="1"
  mmcache.debug="0"
  mmcache.filter=""
  mmcache.shm_max="0"
  mmcache.shm_ttl="0"
  mmcache.shm_prune_period="0"
  mmcache.shm_only="0"
  mmcache.compress="1"

Step 4. Creating cache directory

  mkdir c:tmpmmcache

Configuration Options

mmcache.shm_size
The amount of shared memory (in megabytes) that Turck MMCache will use. "0" means OS default. Default value is "0".
mmcache.cache_dir
The directory that is used for disk cache. Turck MMCache stores precompiled code, session data, content and user entries here. The same data can be stored in shared memory also (for more quick access). Default value is "/tmp/mmcache".
mmcache.enable
Enables or disables Turck MMCache. Should be "1" for enabling or "0" for disabling. Default value is "1".
mmcache.optimizer
Enables or disables internal peephole optimizer which may speed up code execution. Should be "1" for enabling or "0" for disabling. Default value is "1".
mmcache.debug
Enables or disables debug logging. Should be "1" for enabling or "0" for disabling. Default value is "0".
mmcache.check_mtime
Enables or disables PHP file modification checking. Should be "1" for enabling or "0" for disabling. You should set it to "1" if you want to recompile PHP files after modification. Default value is "1".
mmcache.filter
Determine which PHP files must be cached. You may specify the number of patterns (for example "*.php *.phtml") which specifies to cache or not to cache. If pattern starts with the character "!", it means to ignore files which are matched by the following pattern. Default value is "" that means - all PHP scripts will be cached.
mmcache.shm_max
Disables putting large values into shared memory by "mmcache_put()" function. It indicates the largest allowed size in bytes (10240, 10K, 1M). The "0" disables the limit. Default value is "0".
mmcache.shm_ttl
When MMCache fails to get shared memory for new script it removes all scripts which were not accessed at last "shm_ttl" seconds from shared memory. Default value is "0" that means - don't remove any files from shared memory.
mmcache.shm_prune_period
When MMCache fails to get shared memory for new script it tryes to remove old script if the previous try was made more then "shm_prune_period" seconds ago. Default value is "0" that means - don't try to remove any files from shared memory.
mmcache.shm_only
Enables or disables caching of compiled scripts on disk. It has no effect on session data and content caching. Default value is "0" that means - use disk and shared memory for caching.
mmcache.compress
Enables or disables cached content compression. Default value is "1" that means enable compression.
mmcache.keys
mmcache.sessions
mmcache.content
Determine where keys, session data and content will be cached. The possible values are:
"shm_and_disk" - cache data in shared memory and on disk (default value)
"shm" - cache data in shared memory or on disk if shared memory is full or data size greater then "mmcache.shm_max"
"shm_only" - cache data in shared memory
"disk_only" - cache data on disk
"none" - don't cache data
Turck MMCache API

mmcache_put($key, $value, $ttl=0)
puts the $value into shard memory for $ttl seconds.


mmcache_get($key)
returns the value from shared memory which was stored by mmcache_put() or null if it is not exists or was expired.


mmcache_rm($key)
removres the $key from shared memory


mmcache_gc()
removes all expired keys from shared memory


mmcache_lock($lock)
creates a lock with specified name. The lock can be released by function mmcache_unlock() or automatic on the end of request. For Example:
<?php
  mmcache_lock(&quot;count&quot;);
  mmcache_put(&quot;count&quot;,mmcache_get(&quot;count&quot;)+1));
?>
mmcache_unlock($lock)
release lock with specified name


mmcache_set_session_handlers()
install the MMCache session handlers. Since PHP 4.2.0 you can install MMCache session handlers in &quot;php.ini&quot; by &quot;session.save_handler=mmcache&quot;.


mmcache_cache_output($key, $eval_code, $ttl=0)
caches the output of $eval_code in shared memory for $ttl seconds. Output can be removed from cache by calling mmcach_rm() with the same $key. For Example:
<?php mmcache_cache_output(&#39;test&#39;, &#39;echo time(); phpinfo();&#39;, 30); ?>
mmcache_cache_result($key, $eval_code, $ttl=0)
caches the result of $eval_code in shared memory for $ttl seconds. Result can be removed from cache by calling mmcach_rm() with the same $key. For Example:
<?php mmcache_cache_output(&#39;test&#39;, &#39;time().&quot; Hello&quot;;&#39;, 30); ?>
mmcache_cache_page($key, $ttl=0)
caches the full page for $ttl seconds. For Example:
<?php
  mmcache_cache_page($_SERVER[&#39;PHP_SELF&#39;].&#39;?GET=&#39;.serialize($_GET), 30);
  echo time();
  phpinfo();
?>
mmcache_rm_page($key)
removes the page which was cached by mmcache_cache_page() with the same $key from cache


mmcache_encode($filename)
returns the encoded bytecode of compiled file $filename


mmcache_load($code)
loads script which was encoded by mmcache_encode()
WEB interface

Turck MMCache can be managed through web interface script mmcache.php. So you need to put this file on your web site. For security reasons it is recommended to restrict the usage of this script by your local IP.

Since version 2.3.18 admin interface may be protected by password. To generate password run the mmcache_password.php from command line and follow the instruction.
  $ php -q mmcache_password.php
  Changing password for Turck MMCache Web Interface (mmcache.php)

  Enter admin name: admin
  New admin password: mmcache
  Retype new admin password: mmcache

  Add the following lines into your php.ini and restart HTTPD

  mmcache.admin.name=&quot;admin&quot;
  mmcache.admin.password=&quot;$1$0ScD9gkb$nOEmFerNMvQ576hELeLrG0&quot;

If you use mmcache.php in directory that is password-protected by HTTPD then MMCache&#39;s admin name and password must be the same.
Encoder

Turck MMCache. is a PHP Encoder. You can encode PHP scripts in order to distribute them without sources.

Turck MMCache contains only the command line interface to Encoder - encoder.php.
It should be run from command line:
  $ php -q encoder.php

To encode one script do:
  $ php -q encoder.php -f input.php -o output.php

To encode directory do:
  $ php -q encoder.php -rcf input_dir -o output_dir

If you use non command line PHP build, you must set &quot;register_argc_argv = On&quot; in your php.ini.

Jason Sheets has written PHPCoder a GUI front end to the Turck MMCache Encoder.

PHPCoder is a web-based front-end to the Turck MMCache encoding functions and allows you to easily encode your PHP scripts into non-reverisble byte-code. It allows you to set restrictions on the encoded scripts, for example you can lock a script to a particular server IP address, server host name, visitor IP, or even place a time limit on the script so it will expire after x amount of time. PHPCoder also allows you to specify Text, HTML or PHP code that should be prepended and appended to each file before it is encoded, allowing you to easily and securely implement your own licensing scheme.

PHPCoder is available at \\[url=http://phpcoder.shadonet.com\\]http://phpcoder.shadonet.com\\[/url\\]
Standalone Loader

You can use files encoded by Turck MMCache without it. For this reason you must use TurckLoader. It is a regular PHP extension that can be used with other accelerators or without them. It can be loaded on startup or in runtime by dl(). TurckLoader is not need with Turck MMCache, becuse it is already compiled in. For more information about TurckLoader see README.loader file.

Kao 發表於 2004-4-20 11:02

Turck MMCache for PHP

Turck MMCache for PHP 的作者已經到 Zend 工作了  :-X

[url=http://sourceforge.net/forum/forum.php?thread_id=986362&forum_id=236228]http://sourceforge.net/forum/forum.php?thr...forum_id=236228[/url]                    

FIEND 發表於 2004-4-28 04:06

Turck MMCache for PHP

^^!!                    

頁: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.