Re: fscanf and memory
| From: | Tom Rogers | Date: | Thu, 26 Feb 2004 23:57:20 +0000 |
| Subject: | Re: fscanf and memory | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178968@lists.php.net to get a copy of this message | ||
Hi,
Friday, February 27, 2004, 4:48:20 AM, you wrote:
SG> Hi,
SG> I don't know if it's a bug in php but if I do
SG> $fp=fopen("some_file","r");
SG> while (!feof($fp))
SG> {
SG> fscanf($fp, "%d %d",&$var1,&$var2);
SG> // some treatment
SG> }
SG> fclose($fp);
SG> and the file is big enough, php eat up memory like hot cakes.
SG> But if I do
SG> $fp=fopen("some_file","r");
SG> while (!feof($fp))
SG> {
SG> $line = fscanf($fp, "%d %d");
SG> list ($var1, $var2) = $line;
SG> // some treatment
SG> }
SG> fclose($fp);
SG> It work just fine. Seems a problem with fscanf.
SG> Has someone ever experienced this? Any advises?
SG> Oh btw I'm using php 4.3.4 with Apache 1.3.29
SG> Thanks in advance
SG> Sébastien Guay
SG> _________________________________________________________________
SG> MSN Search, le moteur de recherche qui pense comme vous !
SG> http://fr.ca.search.msn.com/
Thats not the way to use scanf, I think you are doing a scanf for each
line in the file. It should be something like:
while(fscanf($fp, "%d %d",&$var1,&$var2)){
//... do something with the values
}
--
regards,
Tom