From: [EMAIL PROTECTED]
Operating system: Windows XP
PHP version: 4.3.0
PHP Bug Type: Sockets related
Bug description: fsockopen does not block
I have code that would connect to a pop server and retrieve email messages,
without using IMAP functions, which worked fine in PHP 4.0 to PHP 4.2.3,
but no longer works correctly in PHP 4.3.0. From what I can tell it seems
that although the socket shows that it is in blocking mode, it acts as
though it is not in blocking mode. The following code demonstrates the
problem.
With the debug statements added to the code and when it gets to the fgets
function, it loops continuously, without reading data from the stream,
until the time limit is reached.
<?php
$hostname = "pop-server";
$port = "110";
$timeout = 30;
global $errno, $errstr;
$fp = fsockopen ($hostname, $port, $errno, $errstr, $timeout);
// debug
print_r (socket_get_status ($fp));
echo "<br>\n";
socket_set_blocking ($fp, TRUE);
// debug
print_r (socket_get_status ($fp));
echo "<br>\n";
$continue = 1;
while ($continue)
{
$chr = fgets ($fp, 1);
$str .= $chr;
// debug
echo "chr = $chr<br>\n";
$array = explode ("\r\n", $str);
if ($str != $array[0])
{
$continue=0;
}
}
fclose ($fp);
?>
Output from version 4.3.0:
Array ( [stream_type] => socket [unread_bytes] => 0 [timed_out] =>
[blocked] => 1 [eof] => )
Array ( [stream_type] => socket [unread_bytes] => 0 [timed_out] =>
[blocked] => 1 [eof] => )
chr =
chr =
chr =
.
. (Loops continuously)
.
chr =
Fatal error: Maximum execution time of 30 seconds exceeded in
f:\httproot\popcorn0.8.2\includes\popcorn.inc on line 110
Output from version 4.2.3:
Array ( [timed_out] => [blocked] => 1 [eof] => [unread_bytes] => 0 )
Array ( [timed_out] => [blocked] => 1 [eof] => [unread_bytes] => 0 )
chr = +
chr = O
chr = K
chr =
chr = C
chr = u
chr = b
chr = i
chr = c
...
chr = .
chr = n
chr = e
chr = t
chr = >
chr =
chr =
I realize that fsockopen, opens the stream in blocking mode by default,
but I had to use socket_set_blocking prior to version 4.3.0 to get it to
work properly. I tried using stream_set_blocking with the same results.
Also, I have tried connecting to multiple POP mail servers with the same
result. Only when I go back to version 4.2.3, does it work properly.
--
Edit bug report at http://bugs.php.net/?id=21573&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=21573&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=21573&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=21573&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=21573&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=21573&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=21573&r=support
Expected behavior: http://bugs.php.net/fix.php?id=21573&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=21573&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=21573&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=21573&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21573&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=21573&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=21573&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=21573&r=gnused