Bug #18373: unread_bytes always 0

From: Date: Tue, 16 Jul 2002 16:35:37 +0000
Subject: Bug #18373: unread_bytes always 0
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-14325@lists.php.net to get a copy of this message
From:             webmaster@darkenemy.com
Operating system: Windows Server Platform
PHP version:      4.2.1
PHP Bug Type:     Sockets related
Bug description:  unread_bytes always 0

After creating a blocking socket with fsockopen, I entered an idle loop.
I've checked the property unread_bytes of the array returned by
socket_get_status. After I got a value of zero bytes, socket_get_status
reports always an unread buffer of zero bytes, also when the server sends
any data. I checked the server logs and I checked the script without
checking socket status. Without checking the socket status, it works
wonderful.

Sample script:

<?php

echo "<html><body><pre>\n";
set_time_limit(0);

$sock = fsockopen("localhost",6667,$errno,$errstr,30);  // Connecting to
dummy ircd
fputs($sock,"NICK PreProcessor\r\n");
fputs($sock,"USER PHP localhost localhost :HyperText Pre Processor\r\n");

while (!feof($sock)) {           // Loop until connection will be closed
  $stat = socket_get_status($sock);
  $queue = $stat[unread_bytes];  // How many bytes to read from socket?
  if ($queue > 0) {
    $data = chop(fgets($sock,128));
    echo $data."\r\n";
    flush();
    $foo = split("[:]",$data);
    if ($foo[0] == "PING ") fputs($sock,"PONG :$foo[1]\r\n");
    $foo = split("[ ]",$data);
    if ($foo[1] == "005") fputs($sock,"JOIN #Channel\r\n");
    if ($foo[3] == ":die") fputs($sock,"QUIT :EOF\r\n");	// retrieved
shutdown script
  } else {
    sleep(1); // Sleep one second and do other things
  }
}

fclose($sock);       // Good bye ...
echo "</pre></body></html>\n";

?>

-- 
Edit bug report at http://bugs.php.net/?id=18373&edit=1
-- 
Fixed in CVS:        http://bugs.php.net/fix.php?id=18373&r=fixedcvs
Fixed in release:    http://bugs.php.net/fix.php?id=18373&r=alreadyfixed
Need backtrace:      http://bugs.php.net/fix.php?id=18373&r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=18373&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18373&r=support
Expected behavior:   http://bugs.php.net/fix.php?id=18373&r=notwrong
Not enough info:     http://bugs.php.net/fix.php?id=18373&r=notenoughinfo
Submitted twice:     http://bugs.php.net/fix.php?id=18373&r=submittedtwice
register_globals:    http://bugs.php.net/fix.php?id=18373&r=globals



Thread (8 messages)

« previous php.bugs (#14325) next »