I have table content with 100,000 records I call function getNameProcess around 200 times
PHP Code with select from database
function getNameProcess($id)
{
$time1=microtime(true);
$baseClass = new MsDatabase();
$query = "select CON_VALUE,CON_ID,CON_CATEGORY from content where CON_ID=$id and CON_VALUE<>'' and CON_CATEGORY='PRO_TITLE'";
$res= $baseClass->query($query,WF_WORKFLOW_DB_NAME);
$time2=microtime(true);
$timeTotal=($time2-$time1);
echo $timeTotal;
return $res[0]["CON_VALUE"];
}
PHP Code with select from public variable
$contentTable=array();
function getNameProcess($id)
{
$time1=microtime(true);
$baseClass = new MsDatabase();
if(empty($GLOBALS['contentTable']))
{
$query = "select CON_VALUE,CON_ID,CON_CATEGORY from content ";
$GLOBALS['contentTable']= $baseClass->query($query,WF_WORKFLOW_DB_NAME_MARKAZE);
}
foreach($GLOBALS['contentTable'] as $R)
{
if($R['CON_ID']==$id && $R['CON_VALUE']!='' && $R['CON_CATEGORY']=='PRO_TITLE' )
{
$time2=microtime(true);
$timeTotal=($time2-$time1);
echo $timeTotal;
return $R["CON_VALUE"];
}
}
return 0;
}
When using database for get process name $totalTime
is 1.2 second and when use public variable totalTime is 3.5 second?
Why I use public variable $totalTime
is greater than when use database?
How to reduce $totalTime
?
thanks