Always create UNIQUE ID without using database - PHP
<p>I have I have static HTML / JS page without any database (I don't need it). However I start fight with some issue. I need to generate random ID which have to be unique(used once and never ever again). </p>

<p><strong>Stardard MySQL way:</strong></p>

<p>On standard application I will do it with storing all used IDs in database
and when needed new one I will simply</p>

<pre><code>// I generate ID here, let's say it's 123
SELECT COUNT(id) FROM table WHERE id = 123
</code></pre>

<p><strong>My solution which may be not the best one:</strong> </p>

<p>I am thinking alternative may be some storing in file</p>

<pre><code>// Let's generate ID here, and make it 123 again

    $handle = fopen("listOfIDs.txt", "r");
    if ($handle) {
        $used = false;
        while (($line = fgets($handle)) !== false) {
            if($line = 123) {
              $used = true;
              break;
          }
        }        
        fclose($handle);
        return $used;
    } else {
        // error opening the file.
    } 
</code></pre>

<p>Dispite the fact I can imagine my option may work it could be super slow when file become bigger.</p>

<p><strong>Question:</strong></p>

<p>What's the best way to keep simple unique IDs without using database.</p>

<p>Edit:
I forgot to mentioned that unique ID have to be numbers only.</p>