Hello, I have a short php script that is heavy on the workload, I am looking for help on ways to speed things up without changing the functionallity of the script. Any ideas would be much appreciated. below is the code (with unimportant proprietary info changed to generic text)
as you will see, its not a large script but sometimes it takes about 60-90 seconds to complete and draw the results in the browser and we are only talking about 200 results. I THINK the slowdown is happening because I am selecing a status from the mysql server inside the initial looped results from the mssql server results
in english.. what this does is: grab records, loop through records and grab statuses from another DB/table, if the status allows it then show the record else dont show the record
---START CODE---
$cur=odbc_exec($odbccnx, "SELECT buncha stuff from mssql2000 server");
while(odbc_fetch_row($cur)) {
$number = odbc_result($cur, 1);
$phone = odbc_result($cur, 2);
$type = odbc_result($cur, 3);
$name = odbc_result($cur, 4);
$state = odbc_result($cur, 5);
$shipdate = substr(odbc_result($cur, 6),0,11);
$statuscur=mysql_db_query(dbname, "select HIGH_PRIORITY status, statusdate, cbdate from tablename where number = '$number' order by attempts desc limit 1");
$row = mysql_fetch_array($statuscur);
$stat = $row[0];
$statdate = $row[1];
$cbdate = substr($row[2],0,10);
$lockcur=mysql_db_query(dbname, "select locked from lock_table where number = '$number'");
$rowlocked = mysql_fetch_array($lockcur);
$islocked = $rowlocked[0];
if ($stat=="Finish" || $stat=="Return" || $stat=="used") {
$show="0";
}
if ($stat=="Pended" && $statdate==$today) {
list($year,$month,$day) = split('-',$statdate);
$year=$year;
$month=$month;
$day=$day;
if ( alarmDaysDiff($year,$month,$day) == 0 )
$alarmmessage .= "today";
else if ( alarmDaysDiff($year,$month,$day) < 0 )
$alarmmessage .= "past";
else if ( alarmDaysDiff($year,$month,$day) >= 1 )
$alarmmessage .= "future";
if ($alarmmessage=="past") { $show="1"; }
if ($alarmmessage=="today") { $show="0"; }
if ($alarmmessage=="future") { $show="0"; }
}
if ($stat=="Hold") {
$show="0";
}
if ($stat=="CB" && $cbdate!=$today) {
list($year,$month,$day) = split('-',$cbdate);
$year=$year;
$month=$month;
$day=$day;
if ( alarmDaysDiff($year,$month,$day) == 0 )
$alarmmessage .= "today";
else if ( alarmDaysDiff($year,$month,$day) < 0 )
$alarmmessage .= "past";
else if ( alarmDaysDiff($year,$month,$day) >= 1 )
$alarmmessage .= "future";
if ($alarmmessage=="past") { $show="1"; }
if ($alarmmessage=="today") { $show="1"; }
if ($alarmmessage=="future") { $show="0"; }
}
if (($stat!="CB" && $selected=="cbvendor") || ($stat!="CB" && $selected=="cbnonvendor")) {
$show="0";
}
if(!$show) {
$count++;
echo"
<tr>
<td></td>
<td>$number</td>
<td>$name</td>
<td>$shipdate</td>
<td>$type</td>
<td>$state</td>
</tr>";
}
$show="";
$alarmmessage="";
}
odbc_close($odbccnx);
echo "</table><br>Total: $count";
----END CODE---