title: PHP While loops making server time out
body: <p>I'm trying to make a simple PHP function to format when the user was last active. I've been awake for a while and the answer just isn't coming to me.</p>
  
  <p>The database connects just fine.</p>
  
  <p>Any idea why my while loops are timing out?</p>
  
  <pre><code>function showActiveUsers(){
  
  $host_name = '#####';
  $database = '#####';
  $user_name = '#####';
  $password = '#####';
  
  $conn = new mysqli($host_name, $user_name, $password, $database);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  } 
  
  $sql = "SELECT * FROM user ORDER BY last_active DESC";
  $result = $conn-&gt;query($sql);
  
  $conn-&gt;close();
  
  $ago = 0;
  $d = 0;
  $h = 0;
  $m = 0;
  
  foreach($result as $check)
  {
      $ago = time()-$check["last_active"];
  
      if($ago&lt;=120)
      {
          echo '&lt;p&gt;'.$check["username"].'&lt;img width="10px" src="res/activedot.png"/&gt;&lt;/p&gt;';
      }
      else
      {
          $d = 0;
          $h = 0;
          $m = 0;
          while($ago&lt;=86400)
          {
              $d++;
              $ago = $ago-86400;
          }
          while($ago&lt;=3600)
          {
              $h++;
              $ago = $ago-3600;
          }
          while($ago&lt;=60)
          {
              $m++;
              $ago = $ago-60;
          }
      }
  
  }
  
  
  }
  </code></pre>
  
  <p>It's probably insanely simple and I've just been awake way too long.</p>