title: php how to write data into json?
body: <p>I am newer for php. I want make php page cache, query data from mysql and store data into json format. </p>
  
  <p>I have many questions:</p>
  
  <ol>
  <li><p>which type of file should I store? <code>.json</code> or <code>.txt</code> or <code>.cache</code>? for I also need use json decode return datas into page. </p></li>
  <li><p>I want use cron tab, make many mysql queries and write into one json file. what write code should I choose? <code>fopen, fwrite</code> or <code>file_get_contents</code> or other command? (do not cover the data, but continue write. I will deleted the file and renewer it at the next cron time)</p></li>
  <li><p>If a multi write into a json data (10 or more mysql query at the same time and write into a same json file, each json child format like <code>{name: ".$row['name']."}</code>), how to completed a top <code>{</code> and bottom <code>}</code> to make a standad json data format?</p>
  
  <p><strong>{</strong> //how to add this one </p>
  
  <p>{name: ".$row['name']."}</p>
  
  <p>{name: ".$row['name']."}</p>
  
  <p>// many name from 10 more mysql queries</p>
  
  <p><strong>}</strong> //and this one</p></li>
  </ol>
  
  <p>Thanks.</p>