title: Is it better to run a cron job every 3 minutes or do a php script only on request if 3 minutes already passed?
body: <p>My problem is quite simple here: I have a php script which retrieves large quantity of csv files from different api, store them in a database (MySQL) and display them to my users. I have to query those api every 3 minutes to get significant data. <strong>Only last data is used, no need to get historical data.</strong></p>
  
  <p><strong>My concern is to avoid querying these api and inserting large amount of data in my database if no one is here to see the page.</strong>  </p>
  
  <p>It is not a problem of rate limits, just thinking about reducing useless requests and inserts into a database.  </p>
  
  <p>My question is the following:  </p>
  
  <ul>
  <li>Is it better to use a cron job every 3 minutes to retrieve data and store them OR</li>
  <li>run a php script if a page is loaded and 3 minutes have passed since last update?</li>
  </ul>
  
  <p>In the first situation, every user will have the last values and data will always be retrieved even if no one is here to see them.<br>
  In the second situation, one user every 3 minutes will retrieve data for all (hence his page will be a little slower than others to load), but if no one is visiting the site, no useless data is stored.</p>
  
  <p>Note:<br>
  Retrieving and inserting data take about 10 seconds.</p>
  
  <p>Thanks for your insights!</p>