I gave that a try but it still seems to be eating up memory.
The code below is an import process that is kicked off by a do while. Do you see anything that could be eating up memory in the code?
Code:
<?php
function import_notes($ss)
{
$query = 'SELECT ndb.X_CDBJOIN,ndb.`Create Timestamp`,ndb.Regarding,cdb.account_id,cdb.contact_id
FROM ndb join cdb on cdb.x_cdbjoin = ndb.x_cdbjoin where ndb.processed = 0 limit 100';
$results = mysql_query($query);
//echo mysql_error();
$num_results = mysql_num_rows($results);
if($num_results > 0)
{
//set purosoap variables.
// $ss = new SugarSoap('http://localhost/' . 'soap.php?wsdl');
//$ss->setDebug(1);
//login to sugar via soap
// $ss->login('admin','password','password');
//check memory usage. If it gets to high then kill the script and start again
$allotted_mem = ini_get('memory_limit');
//debugbreak();
while($row = mysql_fetch_assoc($results))
{
/// debugbreak();
//add the record to sugar via soap
if(isset($row['Regarding']) && $row['Regarding'] != "")
{
//debugbreak();
$date = date("Y-m-d 00:00:00", strtotime($row['Create Timestamp']));
$values = array
(
'name' => substr($row['Regarding'],0,50),
'description' => $row['Regarding'],
'parent_type' => 'Accounts',
'parent_id' => $row['account_id'],
'contact_id' => $row['contact_id'],
'date_entered' => $date,
'date_modified' => $date,
);
$result = $ss->setEntry('Notes',$values);
}
//get the id
if(isset($result['id']))
{
$note_id = $result['id'];
//set the id in the from db
$update_query ='Update ndb set processed = \'1\' where X_CDBJOIN =\''. $row['X_CDBJOIN'] . '\' and `Create Timestamp` = \''. $row['Create Timestamp'] . '\'';
mysql_query($update_query);
$err = mysql_error();
echo "Note Imported\n";
echo "Regarding: ". substr($row['Regarding'],0,50);
}
else
{
echo "ERROR\n";
//set the id in the from db
$update_query ='Update ndb set processed = \'2\' where X_CDBJOIN =\''. $row['X_CDBJOIN'] . '\' and `Create Timestamp` = \''. $row['Create Timestamp'] . '\'';
mysql_query($update_query);
$err = mysql_error();
echo "Note Imported\n";
echo "Regarding: ". substr($row['Regarding'],0,50);
}
$mem_used = memory_get_usage(TRUE) / 1024 / 1024;
echo round(($mem_used / $allotted_mem)*100,2) . " % Memory Utilized\n";
if(round(($mem_used / $allotted_mem)*100,2) > '70')
{
//false means that the script has not completed its work
return FALSE;
}
}
mysql_free_result($results);
$query = 'SELECT ndb.X_CDBJOIN,ndb.`Create Timestamp`,ndb.Regarding,cdb.account_id,cdb.contact_id
FROM ndb join cdb on cdb.x_cdbjoin = ndb.x_cdbjoin where processed = 0 limit 100';
$results = mysql_query($query);
$num_results = mysql_num_rows($results);
mysql_free_result($results);
if($num_results > 0)
{
return FALSE;
}
}
else
{
return TRUE;
}
}
?>
Bookmarks