From: z4ns4tsu at gmail dot com
Operating system: Windows XP
PHP version: 5.2.9
PHP Bug Type: Sockets related
Bug description: socket_read not returning on no more data to read
Description:
------------
I am initiating a socket to an SMTP server to send a message. After
transmitting the EHLO, I need to wait for a variable number of lines to be
returned, so I am using a do{..}while() loop to check if there is nothing
more to be read from the socket before sending the next command. The
program, however, falls into an endless wait because socket_read() is never
returning an empty string (like the documentation says it will) or FALSE
(like some other bug reports say it will).
I have tried with both the PHP_BINARY_READ and PHP_NORMAL_READ flags set
as well as with no flags set at all.
Reproduce code:
---------------
foreach($mail_head as $in) {
$output = "";
$in .= "\r\n";
echo $in;
@socket_write($socket, $in, strlen($in)) or die("Error writing to
socket: " . socket_strerror(socket_last_error()));
do {
$out = false;
$out = socket_read($socket, 1024);
$output .= $out;
} while($out !== false && $out !== '');
if(!preg_match('/^[23]/', $output)) {
die("Error: Mail server did not return the expected response.");
}
}
Expected result:
----------------
EHLO fake.domain
250-this server offers 4 extensions
250-AUTH LOGIN
250-SIZE 30485760
250-HELP
250 AUTH=LOGIN
MAIL FROM:<[email protected]>
250 Requested mail action okay, completed
...
Actual result:
--------------
EHLO fake.domain
<nothing>
--
Edit bug report at http://bugs.php.net/?id=48249&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=48249&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=48249&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=48249&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=48249&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=48249&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=48249&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=48249&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=48249&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=48249&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=48249&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=48249&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=48249&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=48249&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=48249&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48249&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48249&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=48249&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=48249&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=48249&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=48249&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=48249&r=mysqlcfg