最快的 PHP 内存缓存/哈希表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7309354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fastest PHP memory cache/hashtable
提问by thwd
I'm looking for the fastest in-memory cache/hashtable available for PHP.
我正在寻找可用于 PHP 的最快的内存缓存/哈希表。
I will be storing some system-configuration values in it and I'm trying to get the least possible overhead.
我将在其中存储一些系统配置值,并试图获得尽可能少的开销。
The data will be small and granular.
数据将是小而细的。
What would you recommend and why?
你会推荐什么,为什么?
采纳答案by Gordon
If you dont have APC or Memcached installed already (or dont want to use them for this) you can also create a RAM disk. Then use file_get_contents()
and file_put_contents()
where filename is your key and the file content is your value. I dont have numbers for that, but it should be fast.
如果您尚未安装 APC 或 Memcached(或不想为此使用它们),您还可以创建一个 RAM 磁盘。然后使用file_get_contents()
,file_put_contents()
其中文件名是您的键,文件内容是您的值。我没有这方面的数字,但应该很快。
回答by Arnaud Le Blanc
chdbis a read-only hashtable shared across PHP processes: Probably the fastest and less memory-angry one.
Hidefallows to define constants using a .ini file. The constants are defined once, when the php module is started.
APCcan store variables in shared memory, so that they are available to other PHP processes. It has the overhead of serializing and de-serializing variables each time you store and fetch them.
chdb是一个在 PHP 进程之间共享的只读哈希表:可能是最快的,对内存的影响更少。
Hidef允许使用 .ini 文件定义常量。当 php 模块启动时,常量被定义一次。
APC可以将变量存储在共享内存中,以便其他 PHP 进程可以使用它们。每次存储和获取变量时,它都会产生序列化和反序列化变量的开销。
See others: http://pecl.php.net/packages.php?catpid=3&catname=Caching
查看其他人:http: //pecl.php.net/packages.php?catpid=3&catname=Caching
回答by v3rt1g0
APC http://php.net/manual/en/book.apc.php
APC http://php.net/manual/en/book.apc.php
You can use it for optimizing and caching (intermediate) PHP-code
您可以使用它来优化和缓存(中间)PHP 代码
Read this: http://blog.digitalstruct.com/2008/02/27/php-performance-series-caching-techniques/
阅读:http: //blog.digitalstruct.com/2008/02/27/php-performance-series-caching-techniques/
回答by sanmai
- http://www.php.net/manual/en/function.apc-fetch.php
- http://www.php.net/manual/en/function.apc-store.php
- http://www.php.net/manual/en/class.apciterator.php
- http://www.php.net/manual/en/function.apc-fetch.php
- http://www.php.net/manual/en/function.apc-store.php
- http://www.php.net/manual/en/class.apciterator.php
Specific example:
具体例子:
If you're in multi-server environment, then go for Memcached.
如果您处于多服务器环境中,请选择Memcached。