Fastest PHP memory cache/hashtable [closed]

2020-03-01 08:20发布

问题:

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 8 years ago.

I'm looking for the fastest in-memory cache/hashtable available for 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?

回答1:

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.



回答2:

  • chdb is a read-only hashtable shared across PHP processes: Probably the fastest and less memory-angry one.

  • Hidef allows to define constants using a .ini file. The constants are defined once, when the php module is started.

  • APC can 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.

See others: http://pecl.php.net/packages.php?catpid=3&catname=Caching



回答3:

APC http://php.net/manual/en/book.apc.php

You can use it for optimizing and caching (intermediate) PHP-code

Read this: http://blog.digitalstruct.com/2008/02/27/php-performance-series-caching-techniques/



回答4:

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

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php

If you're in multi-server environment, then go for Memcached.



回答5:

If your don't intend to modify data (probably true for your configuration files) then use chdb.