Changeset 176

Show
Ignore:
Timestamp:
01/12/07 17:06:34 (14 years ago)
Author:
exi
Message:

Changes to sync_server.php to reduce the memory load during script execution.

Location:
dev/common
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • dev/common/admin_sync.php

    r162 r176  
    1616    { 
    1717        $html .= "Could not connect to Server:<br/>\n"; 
    18         $html .= $http-getError(); 
     18        $html .= $http->getError(); 
    1919 
    2020        $page->addContext($menubox->generate()); 
     
    7979            unset($data); 
    8080            $results = count($matches[1]); 
     81            if (isset($_REQUEST['itm_overwrite'])) 
     82            { 
     83                $add_qrystr = ''; 
     84            } 
     85            else 
     86            { 
     87                $add_qrystr = ' AND itm_value=0'; 
     88            } 
     89 
    8190            for ($i = 0; $i<$results; $i++) 
    8291            { 
    83                 $update->execute("update kb3_items set itm_externalid='".addslashes($matches[2][$i])."', itm_value='".addslashes($matches[3][$i])."' where itm_name='".addslashes($matches[1][$i])."' limit 1"); 
     92                $update->execute("update kb3_items set itm_externalid='".addslashes($matches[2][$i])."', itm_value='".addslashes($matches[3][$i])."' where itm_name='".addslashes($matches[1][$i])."'".$add_qrystr." limit 1"); 
    8493            } 
    8594            if ($results == 0) 
     
    129138    $html .= "<tr><td width=120><b>Update item values</b></td><td><input type=checkbox name=itm_update id=itm_update"; 
    130139    $html .= " checked=\"checked\"></td></tr>"; 
     140    $html .= "<tr><td width=120><b>Overwrite local values</b></td><td><input type=checkbox name=itm_overwrite id=itm_overwrite"; 
     141    $html .= " checked=\"checked\">(If disabled only values with 0 will be overwritten)</td></tr>"; 
    131142    $html .= '<input type="hidden" name="do" value="sync">'; 
    132143    $html .= '<tr><td width=120></td><td><input type=submit name=submit value="Synchronize now"></td></tr></table></form>'; 
  • dev/common/sync_server.php

    r162 r176  
    9393        $qry->execute("replace into kb3_item_stats (itm_name,kb_host,itm_externalid,itm_value) VALUES ('".addslashes($matches[1][$i])."','".$hostid."','".addslashes($matches[2][$i])."','".addslashes($matches[3][$i])."')"); 
    9494    } 
     95    unset($matches); 
    9596} 
    9697unset($data); 
     
    129130 
    130131$data_array = $data_values = array(); 
     132$lastname = ''; 
    131133$qry->execute('select itm_name, itm_externalid, itm_value from kb3_item_stats order by itm_name asc, itm_value asc'); 
    132134while ($data = $qry->getRow()) 
    133135{ 
     136    // looks like we hit the memory limit so median extraction has to happen here 
     137    if ($lastname != $data['itm_name']) 
     138    { 
     139        // check for lastname due to initialisation 
     140        if ($lastname) 
     141        { 
     142            // get the median value for the item 
     143            $val_cnt = count($data_values[$lastname]); 
     144            $val_cnt = min(ceil($val_cnt/2), $val_cnt)-1; 
     145            $value = $data_values[$lastname][$val_cnt]; 
     146 
     147            $data_array[$lastname]['itm_value'] = $data; 
     148            unset($data_values[$lastname]); 
     149        } 
     150        $lastname = $data['itm_name']; 
     151    } 
    134152    $data_array[$data['itm_name']] = $data; 
    135153    $data_values[$data['itm_name']][] = $data['itm_value']; 
    136154} 
     155unset($data_values); 
    137156 
    138157$content_file .= 'ITEMS_START'; 
    139158foreach ($data_array as $data) 
    140159{ 
    141     // get the median value for every item 
    142     $val_cnt = count($data_values[$data['itm_name']]); 
    143     $val_cnt = min(ceil($val_cnt/2), $val_cnt)-1; 
    144     $value = $data_values[$data['itm_name']][$val_cnt]; 
    145  
    146     $content_file .= '§'.$data['itm_name'].'|'.$data['itm_externalid'].'|'.$value.'-'; 
     160    $content_file .= '§'.$data['itm_name'].'|'.$data['itm_externalid'].'|'.$data['itm_value'].'-'; 
    147161} 
     162unset($data_array); 
    148163 
    149164// return the compressed data back to the client