Reply to Re: About Resource id's

Your name:

Reply:


Posted by Norman Peelman on 10/28/07 13:48

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация