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

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.


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

[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