faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 5 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

Optimice access to files of strings

Jul 19th, 1999 17:42
Julio Garcia,


Well you generally acces to a file database or logs file with a code...


$fp=fopen($filename,"r");
while (!feof($fp)):
$line=fgets($fp,2000);

//Process line
echo $line;

endwhile;


You can optimice code with...

$fp=fopen($filename,"r");
$contents = fread( $fp, filesize( $flename ) );
fclose($fp);

$line=explode("\n",$contents);
$cont=count($line);

for($n1=0;$n1<$cont;$n1++)
{

//Process line  REMEMBER ACCEES WITH ARRAY INDEX

echo $line[$n1];

}

¿Limit.... I process files of 5 Mb...