ID: 10384
User Update by: [EMAIL PROTECTED]
Old-Status: Open
Status: Closed
Bug Type: Sockets related
Operating system: FreeBSD 4.2
PHP Version: 4.0.4pl1
Description: read() buffer memory not freed

This problem appears to be FreeBSD specific.  Still exists with FreeBSD 4.3 but is 
non-existent on Slackware.

Interesting side note:  I had modified the code below and introduced a bug which 
caused Slackware to send a 0 length message.  That is this line:

write($msgsock,$send,strlen($send));

was changed to:

write($msgsock,$msgToSend,strlen($send));

and should have been:

write($msgsock,$msgToSend,strlen($msgToSend));

The variable $send was no longer defined resulting in the correct behavior under 
Slackware of sending no message, however under FreeBSD the full message was sent.

Since this appears to be a bug in the libraries under FreeBSD and NOT PHP related I'm 
closing the ticket.

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

[2001-05-03 13:33:45] [EMAIL PROTECTED]
Problem still exists in 4.0.5

The script originally uses ~2MB resident.  After connections are accepted it begins 
using memory in chunks specified in the read() function until it reaches ~6-6.5MB 
(varies with each run), at which time it continues to run without allocating more 
memory.

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

[2001-04-18 15:27:25] [EMAIL PROTECTED]
Using the  following code:

<?
/* Allow the script to hang around waiting for connections. */
        set_time_limit (0);
        
#####   Connect to DB
        mysql_connect('localhost','chatscript','jen481');

#####   Open log file
        $fp=fopen('chat_log','a');

$outMsgHeader="HTTP/1.1 200 OKrnDate: ";
$outMsgAfterDate=" GMTrnServer: PHPrnConnection: closernTransfer-Encoding: 
chunkedrnContent-Type: text/htmlrnrn";
$outMsgFooter="rnrn";

$sock=open_listen_sock(1089);
if ($sock<0) 
{
        echo "socket() failed: reason: " . strerror ($sock) . "n";
        exit;
}


if (($ret = listen ($sock, 5)) < 0) 
{
        echo "listen() failed: reason: " . strerror ($ret) . "n";
        shutdown($sock,2);
        exit;
}

do 
{

    if (($msgsock = accept_connect($sock)) < 0)
    {
                echo "accept_connect() failed: reason: " . strerror ($msgsock) . "n";
                shutdown($sock,2);
        exit;    
    }
        $ret=read($msgsock,$buf,2048);
        $isPost=strpos($buf,'POST');
        if ($isPost===false) 
        {
                $isGet=strpos($buf,'GET');
                if ($isGET===false) 
                {
                        write($msgsock,' HTTP/1.1 405rn',13);
                }
                else 
                {
                        $startQS=strpos($buf,'?')+1;
                        $endQS=strpos($buf,' ',$startQS);
                        $lenQS=$endQS-$startQS;
                        $QS=substr($buf,$startQS,$lenQS);
                }
        }
        else 
        {
                do   
                {
                        $ret=read($msgsock,$buf,2048);
                        if (substr($buf,0,15)=="Content-length:") 
                        {
                                $conLen=substr($buf,16);
                        }
                } while ($buf != "n");

                // through with headers, now get actual content
                $ret=read($msgsock,$buf,$conLen);
                // $buf now contains the query string
                $QS=$buf;
        }
        $msgToSend=urlencode(procMsg($QS));
        $msgLen=dechex(strlen($msgToSend));
        $sendDate=gmdate('D, d M Y H:i:s');
        $send=$outMsgHeader.$sendDate.$msgLen."rn".$msgToSend.$outMsgFooter;
        write($msgsock,$send,strlen($send));
        $log=$sendDate."t".$QS."t".$msgToSend."n";
        fwrite($fp,$log);
    close ($msgsock);
} while (true);
?>

(The function procMsg() is not relevent as for bug testing is set to return 'test')

Running this script causes memory to be consumed and not released with each 
connection.  I've narrowed the problem down to the read() function as I can affect the 
rate of memory consumption by modifying the length argument.  Evidently the buffer is 
not freed.



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


Full Bug description available at: http://bugs.php.net/?id=10384


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to