From: caesar_iv4 at yahoo dot com
Operating system: win 98 SE
PHP version: 4.3.1
PHP Bug Type: Sockets related
Bug description: socket_read() crashes on client close
I use php 4.3.2 latest cvs
even php 5 and it stil occurs
i am trying to write a small php-based httpdeamon and when i was testing
it with IE6, open the connection and the page starts loading, but when i
click on stop i get the usual crashed program box
here's the script:
<?
function& sock() {
global $SRV;
if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0)
sock_err($sock,"socket_create()");
if (($ret = socket_bind ($sock, $SRV["IP"], $SRV["PORT"])) < 0)
sock_err($sock,"socket_bind()");
if (($ret = socket_listen ($sock, $SRV["MAX_CL"])) < 0)
sock_err($sock,"socket_listen()");
return $sock;
}
function send(&$sock,$msg,$echo=true) {
global $CORE_DUMP;
// socket_write($sock,$msg,strlen($msg));
fwrite($CORE_DUMP,$msg,strlen($msg));
if($echo)
echo $msg;
}
function log_access($ip) {
global $LOG_ACCESS;
$str = date("r")." ".$ip."\n";
fwrite($LOG_ACCESS,$str,strlen($str));
}
function sock_err(&$sock,$fn) {
global $LOG_ERROR;
$str = $fn." failed, reason:
".socket_strerror(socket_last_error($sock));
echo $str;
fwrite($LOG_ERROR,$str,strlen($str));
}
error_reporting (E_ALL);
set_time_limit (0);
ob_implicit_flush();
echo "07\n";
$sock = &sock();
echo "09\n";
do {
echo "11\n";
if (($msgsock = socket_accept(@$sock)) < 0)
sock_err(@$msgsock,"socket_accept()");
echo "14\n";
socket_getpeername(@$msgsock,$ip);
echo "15\n";
log_access($ip);
echo "16\n";
$str = "";
echo "18\n";
$i = 0;
echo "20\n";
while ($msgsock) {
echo "23\n";
if (!$msgsock)
break;
echo $msgsock;
$buf = socket_read($msgsock, 2048, PHP_BINARY_READ);
echo "25\n";
if (!$buf) {
sock_err(@$msgsock,"socket_read()");
break;
}
echo "26\n";
echo "28\n";
}
echo "38\n";
socket_close (@$msgsock);
echo "40\n";
} while (@$sock);
socket_close (@$sock);
?>
the echoes were to pin-point the problem
--
Edit bug report at http://bugs.php.net/?id=22263&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22263&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22263&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22263&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22263&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22263&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22263&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22263&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22263&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22263&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22263&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22263&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22263&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22263&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22263&r=gnused