Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/03/2013, 17:16
Avatar de informacionsys
informacionsys
 
Fecha de Ingreso: mayo-2011
Ubicación: Bogota D.C
Mensajes: 793
Antigüedad: 13 años
Puntos: 76
Leer txt y crear array asociativo

Buenas compañeros

tengo un super problema , y no se como solucionarlo

Subo un archivo txt con mas de 120.000 registros, uso una funcion para generar un array asociativo

Código PHP:
Ver original
  1. function FileMatrizAsociativo($file_name,$separador)
  2.     {
  3.                
  4.         $file  = fopen($file_name,"r");
  5.        
  6.         if($file)
  7.         {
  8.                
  9.         $matriz = array();
  10.         $setarray = array();
  11.                  
  12.         while($recordSet = fgetcsv($file,50000000,$separador))
  13.         {
  14.             array_push($matriz,$recordSet);
  15.         }
  16.         //die(var_dump($matriz));
  17.             $contador = 0;
  18.  
  19.             $output = array();
  20.             //recorro las filas
  21.             for($rows = 1 ; $rows <= count($matriz) -1;$rows++)
  22.             {
  23.                
  24.                 for($cols = 0 ;$cols <= count($matriz[$rows])-1; $cols++)//recorremos las columnas
  25.                 {
  26.                     $setarray[strtolower(trim($matriz[0][$cols]))] = $matriz[$rows][$cols];// creamos un arreglo donde el indice sea el nombre de la cabeza de cada columna
  27.                 }
  28.                 array_push($output,$setarray);
  29.             }
  30.         }
  31.         else
  32.         {
  33.             $output = array();
  34.         }
  35.  
  36.         return $output;
  37.     }
  38.  
  39.  
  40. // ejecuto la funcion
  41.  
  42. FileMatrizAsociativo("archivo.txt",";");

El problema es que me genera un error en tiempo de ejecucion

Allowed memory size of 1073741824 bytes exhausted (tried to allocate 53 bytes) in <b>C:\xampp\htdocs\misitio\carga.php</b> on line <b>1029

La linea 1029 es este segmento de la funcion anterior

Código PHP:
Ver original
  1. $setarray[strtolower(trim($matriz[0][$cols]))] = $matriz[$rows][$cols];

Tengo configurado los tiempos asi:
Código PHP:
Ver original
  1. //parametros php.ini
  2. ini_set("display_errors",1);
  3. ini_set('memory_limit', '-1');
  4. //ini_set("max_execution_time","4000");
  5. ini_set("upload_max_filesize","60M");
  6. ini_set("max_file_uploads","30");
  7. ini_set("session.gc_maxlifetime", "43200");
  8. date_default_timezone_set('America/Bogota');
  9. ini_set("buffering",0);