Persistent storage of PHP variables?

Is it possible to store constant variables in PHP, i.e. finite unmodifiable variables, but which can be read by all users requesting the page?

eg. I will need to use the dictionary on the page, starting with a large (invariant) list of words. What is the best way to do this?

  • Converting a list of words to a tree on the fly with each page load is a complete loss of computing resources and takes a few seconds to load a page.
  • Putting a tree in the file system in the form of subfolders and using file_exists() is fast enough, but uses 4 Kbytes per word, which is a total loss of disk space.
  • Entering words into the database is not possible because I need thousands of page load requests.

What would be a suitable way to store this dictionary?

+4
source share
4 answers

memcached is very popular in php as a way to store stuff in memory that many processes can access http://php.net/manual/en/book.memcached.php

a similar solution could be to use the sqlite shared memory database http://www.sqlite.org/inmemorydb.html

+5
source

I understand that your page should contain a dictionary for an invariant list of words. If the list of words is invariant, and if the resulting dictionary is also invariant, then why not cache the entire content of the page? This will ensure a constant access time for all users.

A common template for this use case is to compute a list of words in a key suitable for searching a data store, such as memcached . Performance seems to be important to you, and in this case, displaying the page requires one unidirectional transition to the data store and virtually no processing.

If users can interact with the word list, it will be time to invalidate the cached page. There again, one single return path to the data warehouse is required.

+2
source

I think a NoSQL database like MongoDB is very suitable for your needs. Additional Information:

+1
source

What happened to the processing of the thousands of download requests database? You know that this was done for you.

Deploy the database solution with the right index, and everything will be fine.

0
source

All Articles