is there a way to permanently cache a text file into memory (php)?
I am creating a site that allows users to search a static text file.
The file is large static data txt file (10mb) that needed to be access/read every time a user searches (which is hopefully often).
Is there a way/technique that loads the content of the file and stored it in memory (and assigned a variable to it) permanently so that it would speed开发者_运维知识库 up the process?
Well, nothing could be permanently in RAM ;)
But if you've already APC
installed, you can store it in there, or use memcached
or Redis
.
Using APC
is the preferable way, cause you'll get opcode cache as well, which give you a performance boost, and it's just a PHP module. No need to setup another daemon.
Have you tried the php shared memory functions? Another possibility might to to use a RAM Disk.
You can use file_get_contents to get the entire file contents into a in-memory string variable.
精彩评论