|
Posted by DiAvOl on 10/28/07 14:51
On Oct 28, 3:48 pm, Norman Peelman <npeel...@cfl.rr.com> wrote:
> DiAvOl wrote:
> > 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
>
> The Resource ID is probably kept track of on a per-script basis and I
> imagine it will roll-over when needed. See:http://us3.php.net/manual/en/language.types.resource.php
>
> Also, why not simply write a script to test your theory? Not sure how
> long it would take... see other reply.
>
> Norm
I wrote a script but it takes too long to reach that number =). I
guess I should not worry about it, but it would be more natural (imo)
to reuse freed resource id slots.
Btw, I checked the source code for fclose but can't understand much
/* {{{ proto bool fclose(resource fp)
Close an open file pointer */
PHPAPI PHP_FUNCTION(fclose)
{
zval **arg1;
php_stream *stream;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1)
== FAILURE) {
WRONG_PARAM_COUNT;
}
PHP_STREAM_TO_ZVAL(stream, arg1);
if (!stream->is_persistent) {
zend_list_delete(stream->rsrc_id);
} else {
php_stream_pclose(stream);
}
RETURN_TRUE;
}
Thanks for your help
Navigation:
[Reply to this message]
|