How to avoid a while for execution before finishing the task?

Asked

Viewed 242 times

2

I’m having a problem doing a query in a Mysql database. This query returns me a lot of data, and this data is sent to make a comparison within a while. Usually it is exceeding the time of my server finishing the execution before making all the comparisons.

I want to know if you have a technique for comparing all records without the execution being interrupted?

It is possible for a progress bar or a percentage to know how much has already been processed?

Below is part of the code I’m using for better understanding.

 while($row=ibase_fetch_object($result)){

   $codigo = $row->CODIGO;
   $saldo  = $row->SALDO;

   $mysqlquery = mysql_query("SELECT * FROM especificacoes_do_produto WHERE edp_interno LIKE '$codigo'");

   if(mysql_num_rows($mysqlquery) != 0){
        mysql_query("UPDATE especificacoes_do_produto SET edp_estoque = '$saldo' WHERE edp_interno='$codigo'");
        $cad_texto = "Atualizado.....";
   } else { 
        $cad_texto = "cadastrar";
   }

 }
  • 1

    I think your question would be: how to set the running time of a PHP script?

  • Have to show the code of the Firebird/inter base query, maybe it is possible to optimize it.

  • 1

    yes this is the sql I’m using.. $sql = "SELECT DISTINCT (items.codigo), items.codigofabricante, items.Descricao, items.fabricante, items.um, (select balance from saldoiten(12,items.codigo,null)) the items balance FROM items items, itensorcamentos io WHERE items.CODIGO = io.ITEMESTOQUE and (items.codigo BETWEEN '100000' AND '39999999') AND (io.DATAINCLUSAO Between '$date $hora_inicio' And '$date $hora_fim') AND (io.FILIAL=12) ORDER BY items.codigo"; @rray

1 answer

1


You can set the time out of a request use the function set_time_limit pass zero as this value to leave time undetermined. Add this line at the beginning of your code:

You can do some 'optimizations' in your code, if possible take the like already the code search is exact and add the clause limit mysql query is not being used anywhere it only serves to count the records.

<?php
set_time_limit(0);

while($row=ibase_fetch_object($result)){

   $codigo = $row->CODIGO;
   $saldo  = $row->SALDO;

   $sql = "SELECT * FROM especificacoes_do_produto WHERE edp_interno = $codigo LIMIT 1";
   $mysqlquery = mysql_query($sql);
  • Query got too big and this error Error 503 Backend fetch failed Backend fetch failed Guru Meditation: XID: 338921723 Varnish cache server @rray

Browser other questions tagged

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