Delay when generating txt file and downloading using php

Asked

Viewed 44 times

0

The problem is the following: The application makes a query in the database like size, color, price, etc... This will be placed in the txt file for later use inside the stock collector. The problem is that one of the options ends up generating 300mil lines and it ends up taking 5-9 minutes to be generated and the customer asked it to be faster... Follows the Code:
**

if($customRadio=='INFANTIL') 
{
    $sql = sqlsrv_query($conn,"
    
    select  
        CONCAT(rtrim(ltrim(pb.codigo_barra)),';',rtrim(ltrim(p.DESC_PROD_NF)),' ',rtrim(ltrim(pc.DESC_COR_PRODUTO)),' ',rtrim(ltrim(pb.GRADE)),';',';') AS 'MIX'
    from PRODUTOS p 
    inner join PRODUTOS_BARRA pb on pb.produto = p.produto and pb.inativo = 0
    inner join PRODUTO_CORES pc on pc.PRODUTO = pb.PRODUTO and pc.COR_PRODUTO = pb.COR_PRODUTO
    where p.INATIVO = 0 and p.STATUS_PRODUTO = 3 AND RTRIM(GRIFFE) <> 'FOOT' and p.LINHA IN ('INFANTIL')
    ORDER BY CODIGO_BARRA
    ");
    
    if ($sql==0){
        } else {
    
        
        while($exibe = sqlsrv_fetch_array($sql)){
           
            $html = $exibe['MIX'];
            
                $arquivo = "MIX_INFANTIL_$hoje.txt";
                $file = fopen($arquivo,'a');
                $quebra = chr(13).chr(10);
                fwrite($file,$html.$quebra);
                fclose($file);
                }   
              
               
                header("Content-Disposition: attachment; filename=".basename($arquivo));    
                readfile($arquivo);
                $file = $arquivo;       
                if (!unlink($file)){
                    echo ("erro ao deletar");
                }
                else{
                    echo ("");
                }
    }
    @sqlsrv_close($conn); //FIM DA CONEX�O 
}

** Does anyone know if there’s a way to make this go faster? Thank you for your attention ;)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.