Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/12/2005, 13:43
Cluster
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 4 meses
Puntos: 129
Cita:
No se si estoy bien en lo que pienso, pero creo que si meto el archivo completo en una variable estoy haciendo que el programa consuma memoria en exceso. O no?
Si, así es .. pero no hay otra forma de procesar un archivo .. la lectura es secuencial de principio a fin -> a una variable (un array por ejemplo) y de ahí lo procesas. ¿que crees que hace: $archivo=fread($contenedor,filesize($nombre)); ? .. exactamente eso mismo .. lo lee .. sólo que en ese caso lo hace hacia una cadena no un array como lo hace file()

Prueba con esta sugerencia:
Cita:
hackajar <matt> yahoo <trot> com
05-Dec-2005 10:17
When working with VERY large files, php tends to fall over sideways and die.

Here is a neat way to pull chunks out of a file very fast and won't stop in mid line, but rater at end of last known line. It pulled a 30+ million line 900meg file through in ~ 24 seconds.

NOTE:
$buf just hold current chunk of data to work with. If you try "$buf .=" (note 'dot' in from of '=') to append $buff, script will come to grinding crawl around 100megs of data, so work with current data then move on!
Código PHP:
//File to be opened
$file "huge.file";
//Open file (DON'T USE a+ pointer will be wrong!)
$fp fopen($file'r');
//Read 16meg chunks
$read 16777216;
//\n Marker
$part 0;

while(!
feof($fp)) {
   
$rbuf fread($fp$read);
   for(
$i=$read;$i || $n == chr(10);$i--) {
       
$n=substr($rbuf$i1);
       if(
$n == chr(10))break;
       
//If we are at the end of the file, just grab the rest and stop loop
       
elseif(feof($fp)) {
           
$i $read;
           
$buf substr($rbuf0$i+1);
           break;
       }
   }
   
//This is the buffer we want to do stuff with, maybe thow to a function?
   
$buf substr($rbuf0$i+1);
   
//Point marker back to last \n point
   
$part ftell($fp)-($read-($i+1));
   
fseek($fp$part);
}
fclose($fp); 
http://www.php.net/manual/en/function.fgets.php

Cita:
Ese archivo es de un juego (warcraft III).
Ok,

Un saludo,