NYCPHP Meetup

NYPHP.org

[nycphp-talk] Memory Limit

Hans Zaunere hans at nyphp.org
Sat Jan 4 17:37:35 EST 2003


--- Kayra Otaner <kayraotaner at yahoo.com> wrote:
> Hi,
> 
> I've been trying to find the correct code to show memory usage and 'unset'
> feature. I was using
> Php cli version 4.1 and there was some sort of gc problem I guess. Here is
> a sample code, it
> basically reads a file and once in a  5000 lines it prints usage status.
> You'll observe that
> memory amount dedicated to script is increasing in time. If you comment
> 'unset()' functions in the
> code below, memory consumption speed will going to increase. I'm using 300
> Mb of access.log file
> so you can observe memory increase after a while. I've checked same code on
> php cli 4.3 and there
> seems to be a fixed but memory dedicated to the script is still increasing
> after some time. 
> 
> $fp = fopen("access.log", "r");
> while ($row = fgets($fp, 10000)) :
> 	$text = $text.$row;

Does:  $text .= $row;   make any difference?

> 	$i++;
> 	if ($i > 5000) {
> 		print_r(getrusage());
> 		unset($text);
> 		$text = $row;
> 		unset($i);
> 		$i = 0;
> 		}
> 	unset($row);
> endwhile;

Does this act any different as far as memory usage (or speed):

$fp = fopen("access.log", "r");
$i = 0;
$text = NULL;
while( $row = fgets($fp, 10000) ) :
   $text .= $row;
   $i++;
   if ($i > 5000) {
      print_r(getrusage());
      $text = $row;
      $i = 0;
   }
endwhile;

Maybe letting Zend/PHP take care of things implicitly shows an improvement? 
I suppose overall script memory usage will increase over time due to some
overhead, but I'm curious as to what/why the overhead is/exists, if there's a
limit, and if it can be totally skirted.  Or, hark, memory leaks?



=====
Hans Zaunere
President, New York PHP
http://nyphp.org
hans at nyphp.org



More information about the talk mailing list