I am trying to implement a very, very large dictionary search to match words in a sentence in PHP. My initial idea was to use the Aho-corasick algorithm, as the Aho-corasick solves my exact problem. I first implemented a Trie in PHP. The Trie, when cached, makes a sufficiently fast dictionary; however, it takes up approximately 3mb of memory. This is not going to scale well in PHP.
Obviously, no matter the data structure we use, a large dictionary will take up a lot of memory. I only need a single instance of the dictionary, since it is static and will not need to be rebuilt.
If this object could be shared between all threads, 3mb of memory is negligible, however, I am unsure of the proper way to share memory between threads in PHP.
How can I share this object between HTTP requests? I cannot see the project scaling when each thread requires 3mb overhead created just by the Trie.