title: Best solution for recording page views in a high traffic web app
body: <p>I'm building a web based directory for a niche industry. I would like to provide a views counter on each listing/profile, similar to how MySpace use to do it in the good old days (come back 90's MySpace, all is forgiven).</p>
  
  <p>I'm using MySQL, and wondering what is the best way to record the data.</p>
  
  <p>Another thread (<a href="https://stackoverflow.com/questions/4762527/what-is-the-best-way-to-count-page-views-in-php-mysql">What is the best way to count page views in PHP/MySQL?</a>) provided the following solution by @dorkitude:</p>
  
  <pre><code>$sample_rate = 100;
  if(mt_rand(1,$sample_rate) == 1) {
      $query = mysql_query(" UPDATE posts SET views = views + {$sample_rate} WHERE id = '{$id}' ");
      // execute query, etc
  }
  </code></pre>
  
  <p>This works on the theory of probability, and was explained by @Suyash as </p>
  
  <blockquote>
    <p>The general idea behind this is that, in theory, it should take 100 tries to hit the number '1' - and so the view count is more or less correct without the constant need to query the database.</p>
  </blockquote>
  
  <p>The thread is dated 2011, and I was wondering if any better solutions had come to light since then.</p>