Categories > TinyButStrong general >

Fatal error: Allowed memory size of 16777216 bytes exhausted

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Valterci
Date: 2006-11-02
Time: 16:42

Fatal error: Allowed memory size of 16777216 bytes exhausted

Hi Skrol,
I receive the message below, trying to show a research:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 4851495 bytes) ......../tbs/tbs_class.php on line 1782

Please Help me
By: Skrol29
Date: 2006-11-02
Time: 19:06

Re: Fatal error: Allowed memory size of 16777216 bytes exhausted

Hi Valterci,

We need more clue to dig the problem.
What TBS version are you using?
Can you debug a bit your PHP code to found after what line this problem appear ?
By: Valterci
Date: 2006-11-04
Time: 22:34

Re: Fatal error: Allowed memory size of 16777216 bytes exhausted

In my application the following errors are shown, however one,
however another one, when I search a great amount of data.
When the amount is small this does not occur:

Fatal error: Maximum execution time of 30 seconds
exceeded in /www/wlinux668/public_html/gestao/tbs/tbs_class.php on line 1193

our

Fatal error: Allowed memory size of 16777216 bytes exhausted
(tried to allocate 593 bytes) in /www/wlinux668/public_html/gestao/tbs/tbs_class.php on line 1193



When I carry through the direct research in mysql,
I obtain a waited result fast, as it can below be seen in exempo:

********
Mostrando registros 41520 - 41540 (41,541 total,
Consulta levou 1.3206 segundos)consulta SQL:
******

This is my SELECT in such a way in the application,
how much in the direct consultation:

SELECT est_entrada.id AS id, est_produto.descricao AS descricao,
est_entrada.quantidade AS qtd,
est_entrada.vr_custounitario AS vr_unitario,
est_estoque.descricao AS estoque,
est_entrada.referencia AS referencia,
est_fornecedor.descricao AS fornecedor, est_entrada.data AS data
FROM est_entrada
INNER JOIN est_estoque ON est_entrada.id_estoque = est_estoque.id
INNER JOIN est_produto ON est_entrada.id_produto = est_produto.id
LEFT JOIN est_saida ON est_saida.id_entrada = est_entrada.id
INNER JOIN est_grupo ON est_subgrupo.id_grupo = est_grupo.id
INNER JOIN est_subgrupo ON est_entrada.id_subgrupo = est_subgrupo.id
INNER JOIN est_fornecedor ON est_entrada.id_fornecedor = est_fornecedor.id
WHERE est_entrada.data >= '1990-01-01'
AND est_entrada.data <= '2006-11-04'
AND est_produto.descricao LIKE '%%'
GROUP BY est_entrada.id
ORDER BY est_estoque.descricao, est_entrada.data
LIMIT 41520 , 30

*******
This is the part of my code that could be intervening, also the functions:

......
PHP
........
$TBS->MergeBlock('blk_est',$cnx_id,$sql_est);
$tt_rec = $TBS->MergeBlock('blk',$cnx_id,$sql);
if (isset($tot_1)) $tot_est_all[] = $tot_1;
if (isset($tot_2)) $tot_data_all[] = $tot_2;
if (isset($tot_1_vr)) $tot_est_all_vr[] = $tot_1_vr;
if (isset($tot_2_vr)) $tot_data_all_vr[] = $tot_2_vr;
mysql_close($cnx_id) ;
$TBS->Show(TBS_OUTPUT);
function f_total($Name,&$CurrRec,$RecNum) {
  global $save_est, $tot_1,$tot_2, $tot_1_vr,$tot_2_vr,$tot_est_all,$tot_data_all,$tot_est_all_vr,$tot_data_all_vr,$save_data,$id_lista;
if (!isset($save_est)) {
    $save_est = '';
    $tot_est_all = array();
  };
  if (!isset($save_data)) {
    $save_data = '';
    $tot_data_all = array();
  };
  if (($save_est!=$CurrRec['estoque']) ){
  if (isset($tot_1)) {
  $tot_est_all[] = $tot_1;
  $tot_data_all[] = $tot_2;
  $tot_est_all_vr[] = $tot_1_vr;
  $tot_data_all_vr[] = $tot_2_vr;
  };
    $tt_item = 0;
    $tot_1 = 0;
    $tot_2 = 0;
    $tot_1_vr = 0;
    $tot_2_vr = 0;
    $save_est= $CurrRec['estoque'];
    $save_data= $CurrRec['data'];
  };
  if (($save_data!=$CurrRec['data']) ){
  if (isset($tot_2)){
  $tot_data_all[] = $tot_2;
  $tot_data_all_vr[] = $tot_2_vr;
  };
    $tot_2 = 0;
    $tot_2_vr = 0;
    $save_data= $CurrRec['data'];
  };
  // Calculate totals
  if ($id_lista=='3'){
  if ($CurrRec['qtd_s']==0) {
  $CurrRec['qtd']=$CurrRec['qtd_e'];
  }else {
  $CurrRec['qtd']=($CurrRec['qtd_e']-$CurrRec['qtd_s']);
  };
  };
  $tot_1 += $CurrRec['qtd'];
  $tot_2 += $CurrRec['qtd'];
  $tot_1_vr += ($CurrRec['qtd']*$CurrRec['vr_unitario']);
  $tot_2_vr += ($CurrRec['qtd']*$CurrRec['vr_unitario']);
  $CurrRec['tt_item']=($CurrRec['qtd']*$CurrRec['vr_unitario']);
  $CurrRec['total'] = 1;
};
function f_seq_est($FieldName,&$CurrVal) {
  global $tot_id, $tot_est_all;
  if (!isset($tot_id)) $tot_id = 0;
  $CurrVal = $tot_est_all[$tot_id];
  $tot_id++;
};
function f_seq_data($FieldName,&$CurrVal) {
  global $tot_id2, $tot_data_all;
  if (!isset($tot_id2)) $tot_id2 = 0;
  $CurrVal = $tot_data_all[$tot_id2];
  $tot_id2++;
};
function f_seq_est_vr($FieldName,&$CurrVal) {
  global $tot_id3, $tot_est_all_vr;
  if (!isset($tot_id3)) $tot_id3 = 0;
  $CurrVal = $tot_est_all_vr[$tot_id3];
  $tot_id3++;
};
function f_seq_data_vr($FieldName,&$CurrVal) {
  global $tot_id4, $tot_data_all_vr;
  if (!isset($tot_id4)) $tot_id4 = 0;
  $CurrVal = $tot_data_all_vr[$tot_id4];
  $tot_id4++;
};

............
HTML
.............

<tr  valign="top">
    <td>[blk.data;frm='dd/mm']</td>
<td>
    <a href="entrada_ficha.php?id_entrada=[blk.id]&id_lista=[var.id_lista]&per_ini=[var.per_ini]&per_fim=[var.per_fim]&id_estoque=[var.id_estoque]&nome_campo=[var.nome_campo]&desc_produto=[var.desc_produto]">
    [blk.id;block=tr;aggregate=qtd:acc,tt_item:acc;ondata=f_soma]</a></td>
    <td>[blk.descricao]&nbsp;[blk.referencia]</td>
    <td>[blk.fornecedor]</td>
    <td align="center"  class="line2">[blk.qtd]</td>
    <td align="right">[blk.vr_unitario;frm='000.000,00']</td>
    <td align="right"  class="line2">[blk.tt_item;frm='000.000,00']</td>
</tr>

  <tr  class="line2">[onshow;when [var.id_agrup]==1;block=tr]
    <td colspan="4"><b><img src="[var.dir_icone]seta_verde.gif" />
    &nbsp;&nbsp;Total do Dia&nbsp;&nbsp;[blk.data;frm='dd/mm/yyyy';block=tr;footergrp=data]</b></td>
     <td align="center"><b>[var.tot_data_all;onformat=f_seq_data]</b></td>
     <td align="center" >&nbsp;</td>
     <td align="right"><b>[var.tot_data_all_vr;frm='000.000,00';onformat=f_seq_data_vr]</b></td>
  </tr>

  <tr  class="line2">
    <td colspan="4"><b><img src="[var.dir_icone]seta_laranja.gif" />
    &nbsp;&nbsp;Total do Estoque&nbsp;&nbsp;[blk.estoque;block=tr;footergrp=estoque;ondata=f_total]
    </b></td>
     <td align="center"><b>[var.tot_est_all;onformat=f_seq_est]</b></td>
     <td align="center">&nbsp;</td>
     <td align="right"><b>[var.tot_est_all_vr;frm='000.000,00';onformat=f_seq_est_vr]</b></td>
  </tr>
<tr class="line1">
     <td colspan="4"><b>>>&nbsp;&nbsp;TOTAL DA PESQUISA</b></td>
     <td align="center"><b>[blk.qtd:acc]</b></td>
     <td align="center">&nbsp;</td>
     <td align="right"><b>[blk.tt_item:acc;frm='000.000,00']</b></td>
</tr>

*******************

I am showing only the part of the code that I imagine either enough
so that you it can guide me on what it is occurring.
*** Note that, for a small amount of data, let us say 700 lines in the result,
I obtain the waited result, however, when the amount is bigger, the cited messages are shown.
By: Valterci
Date: 2006-11-04
Time: 22:36

Re: Fatal error: Allowed memory size of 16777216 bytes exhausted

I am using tbs 3.2.0 rc 2.3, however, I tested with 3.11 and the problem also occurs.
By: Skrol29
Date: 2006-11-04
Time: 22:59

Re: Fatal error: Allowed memory size of 16777216 bytes exhausted

Hi,

It seems that your result is simply very big and will produce HTML page which is very heavy.

You can allow more time execution for your script using the PHP function set_time_limit(). And you can use the MergeOnFly plug-in that will send some parts of the template to the browser in the same time that they are merged. This way, there will be very less information in the buffer (the the Plug-In page for more information).

If you use the MergeOnFly plug-in, I suggest that you use this version not yet plublished :
<?php

/*
********************************************************
TinyButStrong Plug-in: Merge On Fly
Version 1.01, on 2006-11-04, by Skrol29
********************************************************
*/

define('TBS_ONFLY','tbsMergeOnFly');

class tbsMergeOnFly {

    function OnInstall($PackSize=10) {
        $this->PackSize = $PackSize;
        $this->Version = '1.01';
        return array('OnCommand','BeforeMergeBlock','OnMergeSection');
    }

    function OnCommand($PackSize) {
        $this->PackSize = $PackSize;
    }

    function BeforeMergeBlock(&$TplSource,&$BlockBeg,&$BlockEnd,$PrmLst) {
        if ($this->PackSize>0) {
            $Part2 = substr($TplSource,$BlockBeg);
            $this->TBS->Source = substr($TplSource,0,$BlockBeg);
            $this->TBS->Show(TBS_OUTPUT);
            flush();
            $TplSource = $Part2;
            $BlockEnd = $BlockEnd - $BlockBeg;
            $BlockBeg = 0;
            $this->Counter = 0;
        }
    }

    function OnMergeSection(&$Buffer,&$NewPart) {
        if ($this->PackSize>0) {
            $this->Counter++;
            if ($this->Counter>=$this->PackSize) {
                echo $Buffer.$NewPart;
                flush();
                $Buffer = '';
                $NewPart = '';
                $this->Counter = 0;
            }
            $this->PackSize = 0;
        }
    }


}

?>
By: Valterci
Date: 2006-11-04
Time: 23:25

Re: Fatal error: Allowed memory size of 16777216 bytes exhausted

Thanks a lot for its fast reply. I go to implement the solution that you are suggesting and I say the result to you. I am here of Brazil and here they are only 19:21 hr, imagimo that ai either more, my excuses for being occupying its time at the moment where you it could be resting. I am truily grateful for its attention.