ID:               21485
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Verified
 Bug Type:         Sockets related
 Operating System: Win2K/Linux
 PHP Version:      4.3.0
-Assigned To:      
+Assigned To:      wez
 New Comment:

The nature of non-blocking sockets means that your script must always
be prepared to handle a false or zero length return from fgets/fread,
so I'm not worried about that aspect.
However, the feof() does seem to be a problem.
Looking into it...


Previous Comments:
------------------------------------------------------------------------

[2003-01-09 02:48:19] [EMAIL PROTECTED]

I've noticed that I need the sleep() in order to retrieve the data.

The behaviour with blocking/non blocking sockets haven't changed
though, its still the same in php 4.3.0 as it were in previous php
versions.

What has changed is the feof() that never return true.

Regards
/Bjarne

------------------------------------------------------------------------

[2003-01-08 21:40:39] [EMAIL PROTECTED]

It seems that socket_set_blocking($fp,FALSE); results in other peculiar
behaviour.
When connecting to SMTP server, the server sends some data across the
socket right away, usually something identifying the server.

$fp = fsockopen("mail_server", 25);
var_dump(fgets($fp, 1024));
fclose($fp);
returns the server identify string

$fp = fsockopen("mail_server", 25);
socket_set_blocking($fp,FALSE);
var_dump(fgets($fp, 1024));
fclose($fp);

returns (false) 

$fp = fsockopen("mail_server", 25);
sleep(1);
socket_set_blocking($fp,FALSE);
var_dump(fgets($fp, 1024));
fclose($fp);

returns identify string.

The position of the sleep() call can be after socket_set_blocking() as
well.

------------------------------------------------------------------------

[2003-01-07 06:00:14] [EMAIL PROTECTED]

The following code doesn't work with php4.3.0

As foef() never returns true it got stuck in the while()-loop...

When running the same code in php4.2.3 it works as it should so it
seems like a 4.3.0 issue...
( feof() returns true in 4.2.3... )

The scenario consists of the script connecting to a host which
immediatly replies with a textstring; "OK", which in turn is printed
out...

/Regards
Bjarne

// Open a socket and connects to the host
$fp = fsockopen ($myhost, $myport, $errno, $errstr, 30); 

// check for valid filepointer
if (!$fp) 
{ 
   echo "$errstr ($errno)<br>\n"; 
} 
else 
{ 
  // sets the socket to non-blocking
  socket_set_blocking($fp,FALSE); 
  
  // read data from socket upto EOF in 128 byte chunks
  while (!feof($fp)) // <= FAILS IN PHP 4.3.0!!!!!
  { 
    $buffer .= fgets ($fp,128); 
  } 
  // closing socket
  fclose ($fp); 
  
  // printing the buffer
  print "Buffer:" . $buffer;
}

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=21485&edit=1

Reply via email to