Bug #16148 Updated: fread function leaks memory when reading from socket

From: Date: Mon, 18 Mar 2002 20:15:56 +0000
Subject: Bug #16148 Updated: fread function leaks memory when reading from socket
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-2789@lists.php.net to get a copy of this message
ID: 16148 Updated by: wez@php.net Reported By: petri.valisuo@lmf.ericsson.se -Status: Open +Status: Closed Bug Type: Sockets related Operating System: SunOS 5.8 PHP Version: 4.1.2 New Comment: This bug has been fixed in CVS. Previous Comments: ------------------------------------------------------------------------ [2002-03-18 12:33:01] petri.valisuo@lmf.ericsson.se It seems that fread command leaks memory when data is read from a socket. It does not leak memory if it reads from open file descriptor. The speed of the process increse is as fast as the data flow, i.e. all bytes which are read leaks! Here is a program that shows the problem. We have a file server in the port 9229. When connection is opened there and about 250 MB zip file is requested, the process dies after it has received 8 MB of data. If the file is read from an open file, the process size does not increse at all, and it works perfectly. <?php $len=248532882; header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=file.zip"); header("Content-Length: $len"); $pkg_size=1024; if(1) { $sock=fsockopen("localhost", 9229) or die ("Cannot open socket"); fputs($sock, "GET file.zip\r\n"); } else { $sock=fopen("file.zip", "r"); } while(!feof($sock)) { $recv_amount=(($len > $pkg_size) ? ($pkg_size): ($len)); print fread($sock, $recv_amount); $len=$len-$recv_amount; if($len<1) break; } flush(); fclose($sock); ?> Here is the configuration command of PHP 4.1.2 we are using, as reported by the phpinfo(). './configure' '--with-apache=../apache_1.3.23' '--with-ldap=/data/usr/iPlanet/ldapcsdk414' '--prefix=/data' '--enable-memory-limit' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16148&edit=1

« previous php.bugs (#2789) next »