What: I have a PHP script running that awaits socket connections. When I connect to the socket the script prints out the resource ID.
Problem: 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.
Research: I cant find any documentation that would support me(the programmer) needing to control this. I did find the following link were someone states the same issue.
Thoughts: I would think the system would manage this. If I need to manage the resource ID number then how do I do it.
Code snip:
<?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);
}
?>
Help: 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:
A) What could cause unusual increments in the resource id.
B) If determining the root cause of the unusual increment problem is not feasible maybe how to manage the resource id could help.
Findings: 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.
Thanks