Categories > TinyButStrong general >

Max execution time merging block

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Whyrl
Date: 2012-05-18
Time: 17:46

Max execution time merging block

Hello,

Since serveral days I'm searching why tbs can not generating my page...

Here are the information.

First I'm in un sub-template, that looks like this : index.php -> dispatcher.php -> sub-dispatch.php -> page.php

Secondly the page.php is quite simple :

...
// SETTING TBS
if (isset($this)) {
        $TBS = &$this;
} else {
        include_once('../tbs/tbs_class.php');
        $TBS = new clsTinyButStrong;
}

// VARS;
$arr = array();
$iterator = 0;

$sql = "SELECT * FROM t_global_matrix WHERE matrix_nw = '$nwserver' AND matrix_date = '$maxdate' ORDER BY matrix_nw,matrix_clt ASC";
$req = mysql_query($sql);

while($data = mysql_fetch_array($req))
{
        $arr[$iterator] = array();
        $arr[$iterator]['data'] = $data;
        if($data['matrix_option'] == "OPTION 2")
                $arr[$iterator]['class'] = 'ext';
        else
                $arr[$iterator]['class'] = 'nofact';
        $iterator++;
}

$TBS->LoadTemplate('../templates/view_global_matrix.tpl');
$TBS->MergeBlock('blk', 'array', $arr);
$TBS->Show();

The HTML template file is like this :

[...]
<table>
        <thead>
        <tr>
        <th colspan="10">Matrice Globale Sauvegarde de [nwserver.name]</th>
        </tr>
        <tr>
                <td>Client</td>
                <td>NW Server</td>
                <td>Jukebox</td>
                <td>Pool</td>
                <td>Group</td>
                <td>Offre</td>
                <td>Option</td>
                <td>Type Backup</td>
                <td></td>
        </tr>
        </thead>
        <TBODY>
        [blk;block=begin;sub1]
        <TR>
                <TD class='[blk.class]'>[blk_sub1.matrix_clt]</TD>
                <TD class='[blk.class]'>[blk_sub1.matrix_nw]</TD>
                <TD class='[blk.class]'>[blk_sub1.matrix_jbx]</TD>
                <TD class='[blk.class]'>[blk_sub1.matrix_pool]</TD>
                <TD class='[blk.class]'>[blk_sub1.matrix_group]</TD>
                <TD class='[blk.class]'>[blk_sub1.matrix_offre]</TD>
                <TD class='[blk.class]'>[blk_sub1.matrix_option]</TD>
                <TD class='[blk.class]'>[blk_sub1.matrix_offre_type]</TD>
                <TD>(some action link)</TD>
        </TR>
        [blk;block=end]
        </TBODY>
</TABLE>
[...]
[/code

For 250 entries in the $arr array, it take nearly 14 secondes to generate the page.
With XDebug I've done some profiling and I see that it take 12 secondes to execude the f_Xml_FindTag (in two different call).

I've got some time 2000+ entries in the $arr array, so the page don't generate as it exceded 30 seconds, and php don't allow it by default.

So is there a way to optimize this ?
Am I wrong in using TBS ?

Before I use TBS the page was static on generate in less than 1 seconde...
By: Anonymous
Date: 2012-05-18
Time: 23:11

Re: Max execution time merging block

I see that you are doing
[blk;block=begin;sub1]
Yet there is no 'sub' in your PHP query
I would start by testing
<TBODY>
        <TR>
                <TD class='[blk.class]'>[blk.matrix_clt;block=tr;]</TD>
                <TD class='[blk.class]'>[blk.matrix_nw]</TD>
                <TD class='[blk.class]'>[blk.matrix_jbx]</TD>
                <TD class='[blk.class]'>[blk.matrix_pool]</TD>
                <TD class='[blk.class]'>[blk.matrix_group]</TD>
                <TD class='[blk.class]'>[blk.matrix_offre]</TD>
                <TD class='[blk.class]'>[blk.matrix_option]</TD>
                <TD class='[blk.class]'>[blk.matrix_offre_type]</TD>
                <TD>(some action link)</TD>
        </TR>
        </TBODY>

What happens?

Thanks for TBS every day,
TomH
By: Skrol29
Date: 2012-05-19
Time: 02:14

Re: Max execution time merging block

Hello Whyrl,

Your merging is not optimized for two reasons: you are using a sub-block while it is not needed, and you have not defined any sub-block sections (block=...).


So you should replace your PHP loop with :
while($data = mysql_fetch_array($req))
{
        $data['class'] = ($data['matrix_option'] == "OPTION 2") ? 'ext' : 'nofact';
        $arr[] = $data;
}

And then replace your block definition with:
        [blk;block=begin]
        <TR>
                <TD class='[blk.class]'>[blk.matrix_clt]</TD>
                <TD class='[blk.class]'>[blk.matrix_nw]</TD>
                <TD class='[blk.class]'>[blk.matrix_jbx]</TD>
                <TD class='[blk.class]'>[blk.matrix_pool]</TD>
                <TD class='[blk.class]'>[blk.matrix_group]</TD>
                <TD class='[blk.class]'>[blk.matrix_offre]</TD>
                <TD class='[blk.class]'>[blk.matrix_option]</TD>
                <TD class='[blk.class]'>[blk.matrix_offre_type]</TD>
                <TD>(some action link)</TD>
        </TR>
        [blk;block=end]
By: Whyrl
Date: 2012-05-30
Time: 09:51

Re: Max execution time merging block

Sorry I was on hollyday, I will test this on see what it does. I will tell you if it's better.
In any case, thanks for the answers !