|
Posted by DiAvOl on 10/27/07 12:17
Hello,
I am using a simple php server that I wrote and have some questions
related to the resource id's. When a new client connects to the server
or the server opens a file the Resource id number increases normally,
but when the server closes the socket and the file and then a new
client connects or file opens, the Resource id still increases without
reseting to the previous closed id's.
For example:
Client connects to the server...accept();
Client fd: Resource id #1
client quits.... fclose/socket_close
Client connects to the server...accept();
Client fd: Resource id #2
client quits.... fclose/socket_close
....
....
....
Client connects to the server...accept();
Client fd: Resource id #12456
Shouldn't the resource id reset to #1 when the second client
connected ? Can this behaviour cause problems to the server ?
I wrote a simple socket server and client to demonstrate this:
server:
----------
<?php
set_time_limit(0);
$socket = stream_socket_server("tcp://0.0.0.0:6000", $errno, $errstr);
if (!$socket) {
echo "$errstr ($errno)<br />\n";
} else {
while ($conn = stream_socket_accept($socket)) {
testme();
testme();
testme();
print("Client fd: ".$conn." \n");
fclose($conn);
echo '$socket is resource = ' . (is_resource($conn) ? 'true':
'false')."\n";
}
fclose($socket);
}
function testme() {
$fp = fopen('testfdss','a');
fclose($fp);
echo '$file_pointer is resource = ' . (is_resource($p) ? 'true':
'false')."\n";
}
?>
client:
---------
<?php
set_time_limit(0);
while(true) {
$fp = fsockopen('127.0.0.1',6000,$errno,$errstr,(float) 1);
if (!$fp) {
print("error()\n");
}
fclose($fp);
}
?>
Thanks for your help and sorry for my (bad) english
Navigation:
[Reply to this message]
|