title: How to serialize and unserialize a large file in PHP?
body: <p>I have a HUGE complex data structure (TRIE) that I need to store for later use.</p>
  
  <p>So, I'm using serialize/unserialize (please suggest any better method if any):</p>
  
  <pre><code>$fp = fopen("serialized_trie.txt","w+");
  fwrite($fp,serialize($root));
  fclose($fp);
  
  $root = unserialize(file_get_contents("serialized_trie.txt"));
  </code></pre>
  
  <p>The trie itself is made from 1 million words. So its a big trie.</p>
  
  <p>I need to somehow store this trie. Writing such a big trie to file takes huge amount of time. And file_get_contents in unserialize would cause entire file to be loaded in memory.</p>
  
  <p>Do I need to use a binary file instead of txt file? How?</p>
  
  <p>Also I've read about 3 techniques to store:
  serialize,
  json_encode,
  var_export</p>
  
  <p>Do I need to use json_encode or var_export method in this case?</p>
  
  <p>How do I QUICKLY store the trie and retrieve it? </p>