How to prevent a while to execution before finishing the task?

2

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

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

Is it 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 a 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";
   }

 }
    
asked by anonymous 19.02.2015 / 00:27

1 answer

1

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

You can do some 'optimizations' in your code, if possible take out like since the code search is exact and add the limit clause the mysql query is not being used nowhere is it just 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);
    
19.02.2015 / 01:10