title: Socket resource id overflowing
body: <p><strong>What:</strong> I have a PHP script running that awaits socket connections. When I connect to the socket the script prints out the resource ID. </p>
  
  <p><strong>Problem:</strong> The resource ID does not increment by 1 instead by an average of 306,000. This is of course reaching a bigger problem and overflowing. Causing my code to eventually break. </p>
  
  <p><strong>Research:</strong> I cant find any documentation that would support me(the programmer) needing to control this. I did find the <a href="http://bytes.com/topic/php/answers/729100-about-resource-ids" rel="nofollow">following link</a> were someone states the same issue.</p>
  
  <p><strong>Thoughts:</strong> I would think the system would manage this. If I need to manage the resource ID number then how do I do it.</p>
  
  <p><strong>Code snip:</strong></p>
  
  <pre><code>&lt;?php
  chdir( dirname ( __FILE__ ) );
  echo "Waiting for port!\n";
  $file = 'change.txt';//change query
  
  do{
  $sock = @socket_create_listen('12346'); //port im listening too
  sleep(1);
  }
  while(!(@socket_getsockname($sock, $addr, $port))); 
  
  echo "Server Listening on $addr:$port\n"; 
  socket_set_nonblock($sock);
  echo"Awaiting Connection\n";
  
  while(true)
  {
      if($newc = @socket_accept($sock))
      {
          socket_set_nonblock($newc);
          echo "Client $newc has connected\n";
  
      }
      $current = file_get_contents($file);
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>Help:</strong> The idea is (If you continuously connect to the socket the resource ID would overflow). My code is far to large to paste in, but I reduced it to show the problem: </p>
  
  <p>A) What could cause unusual increments in the resource id.</p>
  
  <p>B) If determining the root cause of the unusual increment problem is not feasible maybe how to manage the resource id could help.</p>
  
  <p><strong>Findings:</strong> The last command "file_get_contents..." if this line is commented out the code works correctly and the resource id is incremented properly. If not commented out and a sleep is added the increment value is much better but not correct (ie jump 5 or 6 values). Im not sure whats really going on though.</p>
  
  <p>Thanks</p>