From:             Xuefer at 21cn dot com
Operating system: -
PHP version:      4.3.4RC1
PHP Bug Type:     Feature/Change Request
Bug description:  faster client lookup after socket_select

Description:
------------
it's slow that phpscript itself have to loop through $fds and use in_array
to know which client is sending data

$allfds[0] = socket_create(...);
$clients[0] = new MyClient($allfds[0]);
...

$count = socket_select($fds);
for ($i = 0; $i < FDSIZE; $i ++) {
  if (in_array($fds, $allfds[$i])) {
    $clients[$i]->processIncomingData();
  }
}
larger FDSIZE make script slower

i'd suggest $fd resource store more information: ID
int socket_set_id(source $sock)
int socket_get_id(source $sock)

$allfds[0] = socket_create(...);
$clients[0] = new MyClient($allfds[0]);
socket_set_id($allfds[0], 0);
$allfds[1] = socket_create(...);
$clients[1] = new MyClient($allfds[1]);
socket_set_id($allfds[1], 1);

$count = socket_select($fds);
for ($i = 0; $i < $count; $i ++) {
  $id = socket_get_id($fds[$i]);
  $clients[$id]->processIncomingData();
}
speed is not depend on FDSIZE



-- 
Edit bug report at http://bugs.php.net/?id=25769&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25769&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25769&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25769&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25769&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25769&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25769&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25769&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25769&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25769&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25769&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25769&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25769&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25769&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25769&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25769&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25769&r=float

Reply via email to