title: PHP script takes too long and times out
body: <p>When I add the function below to my PHP page, it times out trying to execute the script. What's wrong with it?</p>
  
  <pre><code>include ('config.php');
  
  function GenerateTransID() {    
      $unique_ref_length = 9;  
      $unique_ref_found = false;  
      $possible_chars = "23456789BCDFGHJKMNPQRSTVWXYZ";  
      while (!$unique_ref_found) {  
          $unique_ref = "";  
          $i = 0;  
          while ($i &lt; $unique_ref_length) {  
              $char = substr($possible_chars, mt_rand(0, strlen($possible_chars)-1), 1);  
              $unique_ref .= $char;  
              $i++;  
          }
  
          $tmp_id = "TR-" . $unique_ref;
          $unique_ref = $tmp_id;
          $query = "SELECT `transactionID` FROM `payment` WHERE `transactionID`='$unique_ref'";  
          $result = mysql_query($query) or die(mysql_error().' '.$query); 
  
          if (mysql_num_rows($result)==0) {  
              $unique_ref_found = true;  
  
          }  
  
      }  
      return $unique_ref;         
  }
  </code></pre>