From:             [EMAIL PROTECTED]
Operating system: Linux, BSD and Windows
PHP version:      4.0 Latest CVS (06/04/2001)
PHP Bug Type:     Sockets related
Bug description:  fgets causes memory leaks

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.0\r\n\r\n");
  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.0\r\n\r\n");
  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.]


-- 
Edit Bug report at: http://bugs.php.net/?id=10204&edit=1



-- 
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