Greetings, I have a transition page which sometimes seems to take forever to load. I inserted some timestamps throughout the code, and found that the problem seems to be around a mysql query. The query searches a table that is about 800 rows, which makes me believe it shouldn't be taking this long. There are no-cache headers at the top, but I'm not sure if that's the problem here...
Here are the headers at the top...
header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
header( "Cache-Control: post-check=1,pre-check=2" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
function setExpires($expires) {
header( 'Expires: '.gmdate('D, d M Y H:i:s', time()+$expires).'GMT');
}
setExpires(5);
Here is the code I'm running that seems to cause the problem...
$t4=time();
$r=array();
$s=array();
$t=array();
$duplicate = 'yes';
while($duplicate == 'yes'){
$sessionID = rand();
$r[]=time();
$result = mysql_query("SELECT COUNT(sessID) FROM table WHERE sessID = '$sessionID'") or die(mysql_error());
$s[]=time();
while($row = mysql_fetch_array($result)){
$t[]=time();
if($row['COUNT(sessID)'] == 0){$duplicate = 'no';}
}
}
$t5=time();
Here is an example of what all the timestamps have been outputting:
$t4=1200454479
$t5=1200454507
$r[0]=1200454479
$s[0]=1200454507
$t[0]=1200454507
This of course shows that:
$result = mysql_query("SELECT COUNT(sessID) FROM table WHERE sessID = '$sessionID'") or die(mysql_error());
is what is taking so long.
I just can't figure out what's messing with this so bad. The page uses header(Location: ...) to redirect the user after this script has been run...is that a problem? I don't think so, because I've changed it to a JS redirect and the same problem occurs.
It is so strange how it only happens in IE (6 and 7 for sure). A lot of times, it works just fine, but if I leave and come back an hour later, the first time I try it, the problem happens (and then after that it's ok). And sometimes, the problem doesn't happen until the third time I run the script....
Really, any help would be appreciated, as this has been driving me up the wall for the last two weeks.