[PHP-DEV] PHP 4.0 Bug #10204 Updated: fgets causes memory leaks
ID: 10204 User Update by: [EMAIL PROTECTED] Old-Status: Feedback Status: Open Bug Type: Sockets related Description: fgets causes memory leaks Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. No, that's what the unset is for. Anyways, here's memory statistics. On loading script one: 3740kb RAM used after two iterations (RAM should not increase above this level). After 5 minutes: 4130kb. Cf script two: 3752kb RAM used initially, and 3752kb after 5 minutes. These statistics aren't especially dramatic, but in other conditions it can be catastrophic. Regarding fclose, no this doesn't help. There is a problem with fgets but not fread. Previous Comments: --- [2001-04-06 09:19:49] [EMAIL PROTECTED] 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. --- [2001-04-06 08:54:33] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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.] --- Full Bug description available at: http://bugs.php.net/?id=10204 -- 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]
[PHP-DEV] PHP 4.0 Bug #10204 Updated: fgets causes memory leaks
ID: 10204 User Update by: [EMAIL PROTECTED] Status: Open Bug Type: Sockets related Description: fgets causes memory leaks Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. No, that's what the unset is for. Anyways, here's memory statistics. On loading script one: 3740kb RAM used after two iterations (RAM should not increase above this level). After 5 minutes: 4130kb. Cf script two: 3752kb RAM used initially, and 3752kb after 5 minutes. These statistics aren't especially dramatic, but in other conditions it can be catastrophic. Regarding fclose, no this doesn't help. There is a problem with fgets but not fread. Previous Comments: --- [2001-04-09 06:58:37] [EMAIL PROTECTED] Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. No, that's what the unset is for. Anyways, here's memory statistics. On loading script one: 3740kb RAM used after two iterations (RAM should not increase above this level). After 5 minutes: 4130kb. Cf script two: 3752kb RAM used initially, and 3752kb after 5 minutes. These statistics aren't especially dramatic, but in other conditions it can be catastrophic. Regarding fclose, no this doesn't help. There is a problem with fgets but not fread. --- [2001-04-06 09:19:49] [EMAIL PROTECTED] 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. --- [2001-04-06 08:54:33] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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.] --- Full Bug description available at: http://bugs.php.net/?id=10204 -- 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]
[PHP-DEV] PHP 4.0 Bug #10204 Updated: fgets causes memory leaks
ID: 10204 Updated by: wez Reported By: [EMAIL PROTECTED] Old-Status: Open Status: Feedback Bug Type: Sockets related Assigned To: Comments: Sorry - I somehow missed the unset. However, unset just removes the variable from the symbol table - try using $page = null instead. I am in the process of working on a file abstraction for this stuff, so it will be rewritten. The wierd thing is that I really can't see why fgets would behave differently from fread. Maybe I haven't looked hard enough. Please let me know if $page = null works around the problem for now. Previous Comments: --- [2001-04-09 07:29:57] [EMAIL PROTECTED] Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. No, that's what the unset is for. Anyways, here's memory statistics. On loading script one: 3740kb RAM used after two iterations (RAM should not increase above this level). After 5 minutes: 4130kb. Cf script two: 3752kb RAM used initially, and 3752kb after 5 minutes. These statistics aren't especially dramatic, but in other conditions it can be catastrophic. Regarding fclose, no this doesn't help. There is a problem with fgets but not fread. --- [2001-04-09 06:58:37] [EMAIL PROTECTED] Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. No, that's what the unset is for. Anyways, here's memory statistics. On loading script one: 3740kb RAM used after two iterations (RAM should not increase above this level). After 5 minutes: 4130kb. Cf script two: 3752kb RAM used initially, and 3752kb after 5 minutes. These statistics aren't especially dramatic, but in other conditions it can be catastrophic. Regarding fclose, no this doesn't help. There is a problem with fgets but not fread. --- [2001-04-06 09:19:49] [EMAIL PROTECTED] 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. --- [2001-04-06 08:54:33] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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.] --- The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online. ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=10204edit=2 -- 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]
[PHP-DEV] PHP 4.0 Bug #10204 Updated: fgets causes memory leaks
ID: 10204 User Update by: [EMAIL PROTECTED] Old-Status: Feedback Status: Open Bug Type: Sockets related Description: fgets causes memory leaks I am in the process of working on a file abstraction for this stuff, so it will be rewritten. Hmm. I'm already using an abstraction layer; Net_Socket from PEAR. I had to modify the readLine method to read a byte at a time until it encounters \n to workaround the fgets bug. Maybe I haven't looked hard enough. Please let me know if $page = null works around the problem for now. No it doesn't. Previous Comments: --- [2001-04-09 07:57:22] [EMAIL PROTECTED] Sorry - I somehow missed the unset. However, unset just removes the variable from the symbol table - try using $page = null instead. I am in the process of working on a file abstraction for this stuff, so it will be rewritten. The wierd thing is that I really can't see why fgets would behave differently from fread. Maybe I haven't looked hard enough. Please let me know if $page = null works around the problem for now. --- [2001-04-09 07:29:57] [EMAIL PROTECTED] Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. No, that's what the unset is for. Anyways, here's memory statistics. On loading script one: 3740kb RAM used after two iterations (RAM should not increase above this level). After 5 minutes: 4130kb. Cf script two: 3752kb RAM used initially, and 3752kb after 5 minutes. These statistics aren't especially dramatic, but in other conditions it can be catastrophic. Regarding fclose, no this doesn't help. There is a problem with fgets but not fread. --- [2001-04-09 06:58:37] [EMAIL PROTECTED] Um, yes, the memory usage increases because you are appending an infinite number of copies of the google page to your $page variable. No, that's what the unset is for. Anyways, here's memory statistics. On loading script one: 3740kb RAM used after two iterations (RAM should not increase above this level). After 5 minutes: 4130kb. Cf script two: 3752kb RAM used initially, and 3752kb after 5 minutes. These statistics aren't especially dramatic, but in other conditions it can be catastrophic. Regarding fclose, no this doesn't help. There is a problem with fgets but not fread. --- [2001-04-06 09:19:49] [EMAIL PROTECTED] 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. --- [2001-04-06 08:54:33] [EMAIL PROTECTED] 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. --- The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online. Full Bug description available at: http://bugs.php.net/?id=10204 -- 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]
[PHP-DEV] PHP 4.0 Bug #10204 Updated: fgets causes memory leaks
ID: 10204 Updated by: wez Reported By: [EMAIL PROTECTED] Status: Open Bug Type: Sockets related Assigned To: Comments: 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. Previous Comments: --- [2001-04-06 07:54:22] [EMAIL PROTECTED] 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=10204edit=2 -- 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]
[PHP-DEV] PHP 4.0 Bug #10204 Updated: fgets causes memory leaks
ID: 10204 Updated by: wez Reported By: [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] 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=10204edit=2 -- 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]