Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/04/2008, 07:50
anibal_cdf
 
Fecha de Ingreso: marzo-2007
Mensajes: 180
Antigüedad: 17 años, 1 mes
Puntos: 0
Pregunta tengo un script con bucles y funciones que tarda mucho, como puedo hacer ?

buenas gente !
tengo un script que hice yo, lo primero que hace es leer un archivo y luego con un for lo va pasando a una matriz a diferentes columnas (hay varios if), luego de eso se trabaja con el array convirtiendo varias cosas y armando una variable que luego se pasa a un xml.

el tema es que lleva mucho tiempo y solo me lo hace con archivos de pruebas de menos de 1mb mas o menos , pero el archivo que tengo q usar pesa como 34mb, y me da tiempo excedido.
aunque le ponga el set_time_limit(0); no funciona, se queda cargando como 20 minutos y despues no hace nada.

alguna ayuda o recomendacion ?

poner una pausa o alguna manera de hacer algo para que espero, tocar un link y seguir, o algo asi ?






aca les copio el codigo de cuando pasa el archivo a array, hay cosas medias rebuscadas, pero es que era algo simple y despues se fue ampliando, encima hay manejo de caracteres raros de utf8, etc.


Código PHP:
$archivo="mw2_a_abhiks.dict";

set_time_limit(0);

$fp fopen($archivo,'r');

if (
file_exists($archivo))
{
    
$array file($archivo);

    
$newentry=0;
    
$line=0;
    
$page=1
    
$pagedict=0
    for (
$i=0;$i<count($array);$i++)
    {
        
        
$textline=$array[$i];
        
$textline=str_replace(" ,",",",$textline);
        
        
$textline3=substr($array[$i],0,2);
        if (
$textline3=='==' )
        {
            
$newentry++;
            
$line=0;
        }
        else
        {
            
$line++;
        }
        
        if (
$line==4)
        {
            ${
'matriz'.$newentry}[1]=rtrim($textline); // HK
            
if ((${'matriz'.$newentry}[1]) && (${'matriz'.($newentry-1)}[1]) && (strcmp(${'matriz'.$newentry}[1],${'matriz'.($newentry-1)}[1])==0)) // compara hk con hk anterior y resetea el newentry
            
{
                ${
'matriz'.$newentry}[6]='';
                
$newentry--;
                
$page--;
            }
            
        }
        elseif (
$line==6)
        {
            
            ${
'matriz'.$newentry}[2]=substr($textline,2,strpos($textline,"]")-2); // HK con simbolos
            
${'matriz'.$newentry}[3].="---> ".substr($textline,strpos($textline,"]")+1); // Definicion
            
$hksimbolx=rtrim(ltrim(${'matriz'.$newentry}[2]));
            
$hkraiz=strstr(makeSafeEntities($hksimbolx),"&radic;"); // toma desde la primer raiz hasta el final , √
            
$hkraiz=substr($hkraiz,8); // tomamos desde la raiz contando 8 caracteres para no tomar los caracteres del simbolo que son √ mas un espacio.
            
$hkraizlen=strlen(makeSafeEntities($hkraiz));
            
$hksimbollen=strlen(makeSafeEntities($hksimbolx));
            
$diflen=$hksimbollen-$hkraizlen;
            
$hkprevraiz=rtrim(substr(makeSafeEntities($hksimbolx),0,$diflen)); // previo hasta raiz
            
$hkprevlen=strlen($hkprevraiz);
            
$hksimbol=$hkprevraiz.$hkraiz;
            ${
'matriz'.$newentry}[4]=$hkprevraiz;
            ${
'matriz'.$newentry}[5]=$hkraiz;
        }
        if (
$line>&& $textline3!='==')
        {
            ${
'matriz'.$newentry}[3].=$textline// graba definicion
        
}
        if (
$textline3=="1[" || $textline3=="2[")
        {
            ${
'matriz'.$newentry}[0]=$page// Almacena si es una nueva pagina
            
$page++;
        }

        ${
'matriz'.($newentry)}[6].=$textline// dict orig

    
// fin for
    
    
// fin if file exists