The Little Guy Posted September 12, 2008 Share Posted September 12, 2008 I have the following code, it takes forever to run. I have tested it on ~ 400+ returned results from the database. What part of this is making it take so long? while($row = mysql_fetch_array($sql)){ list($dat,$time) = explode(" ",$row['date']); /* Generate Stats For Today */ if($dat == date("Y-m-d")) $totalToday++; if($dat == date("Y-m-d") && !in_array($row['ip'],$ipArrayToday)){ $totalTodayUnique++; array_push($ipArrayToday,$row['ip']); } /* Generate Yesterday's Stats */ if($dat == date("Y-m-d",strtotime('-1 day'))) $totalYesterDay++; if($dat == date("Y-m-d",strtotime('-1 day')) && !in_array($row['ip'],$ipArrayYesterDay)){ $totalYesterDayUnique++; array_push($ipArrayYesterDay,$row['ip']); } } Link to comment https://forums.phpfreaks.com/topic/123990-solved-while-loop-takes-too-long-to-run/ Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 1) Why are you exploding the date from MySQL instead of just doing it in the query? 2) Why are you using array_push()? 3) Try timing various parts of the loop. Link to comment https://forums.phpfreaks.com/topic/123990-solved-while-loop-takes-too-long-to-run/#findComment-640081 Share on other sites More sharing options...
The Little Guy Posted September 12, 2008 Author Share Posted September 12, 2008 problem solved, I moved the date functions outside of the loop, they were slowing them down, then I only had to do it 2 times instead of 400 * 4 times. Link to comment https://forums.phpfreaks.com/topic/123990-solved-while-loop-takes-too-long-to-run/#findComment-640084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.