PHP 4.0 Bug #10204 Updated: fgets causes memory leaks

From: Date: Fri, 06 Apr 2001 13:19:49 +0000
Subject: PHP 4.0 Bug #10204 Updated: fgets causes memory leaks
Groups: php.dev 
Request: Send a blank email to php-dev+get-51034@lists.php.net to get a copy of this message
ID: 10204 Updated by: wez Reported By: pallmall@hushmail.com Old-Status: Open Status: Feedback Bug Type: Sockets related Assigned To: Comments: Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. I can't see any leak in PHP - no leaks are reported by the memory manager. Can you give me more information about how the memory usage increases, and what you would expect it to be? Could you try explicitly fclose()ing your $fps too - you might find it useful in reducing memory cost. --Wez. Previous Comments: --------------------------------------------------------------------------- [2001-04-06 08:54:33] wez@php.net I noticed this last night in the socket code: it uses a simple read-buffering scheme where the read buffer will only grow, so we are effectively storing the everything we have read in memory. However, I would expect the behaviour to be the same with fread. I take it the memory usage returns to normal once the page has completed? --Wez. --------------------------------------------------------------------------- [2001-04-06 07:54:22] pallmall@hushmail.com Try this script (tested on windows, linux and open BSD(: <?php set_time_limit(0); while (1) { unset($page); print "iteration ". ++$c; $fp = fsockopen("google.com", 80); fwrite($fp, "GET / HTTP/1.0rnrn"); while (!feof($fp)) { $page .= fgets($fp, 1000); } } ?> Run it with top or whatever running and watch the memory usage go up and up (not especially quickly because the page is small, but in certain situations I've had memory chewage of 1mb/minute). Now cf. <?php set_time_limit(0); while (1) { unset($page); print "iteration ". ++$c; $fp = fsockopen("google.com", 80); fwrite($fp, "GET / HTTP/1.0rnrn"); while (!feof($fp)) { $page .= fread($fp, 1000); } } ?> Memory usage remains constant here. [This meant I had to rewrite the readLine method in Net_Socket to use fread instead of fgets.] --------------------------------------------------------------------------- ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=10204&edit=2

« previous php.dev (#51034) next »