php - Improving script execution time -


i want improve execution time of insert query, because webhost not change max_execution_time. script below contains test wallclock execution time. results in 22 seconds execution time way long because webhost keeps default @ 30 seconds. after code below, more code needs executed. reference, there 1000 players in tblplayers.

$time_start = microtime(true);  $sqltotalpoints = array(); $sqlcompetingplayers = "select id tblplayers game='" . $gamenumber. "' , joined='1'"; $resultcompetingplayers = mysql_query($sqlcompetingplayers); while($row= mysql_fetch_array($resultcompetingplayers)) {     $playerid = $row['id'];     $sqlalreadyhaspoints = "select playerid tblplayerpoints playerid='" . $playerid . "'";     $resultalreadyhaspoints = mysql_query($sqlalreadyhaspoints);     $pointsrowfound = mysql_num_rows($resultalreadyhaspoints);     if($pointsrowfound < 1 ) {         $sqltotalpoints[] = '("' . $gamenumber . '", "fps", "' . $playerid . '", "0")';     } } echo 'insert tblplayerpoints (game,gamenaam,playerid,pointscollected) values ' . implode(',',$sqltotalpoints);  $time_end = microtime(true); $execution_time = ($time_end - $time_start); echo '<b>total execution time:</b> '.$execution_time.' secs'; 

this results in correct insert statement , total execution time of 22 seconds.

i used have insert inside while loop instead of imploding execution time worse.

here single sql statement you, 1 different other 1 posted add new rows if 1 not exist.

insert `tblplayerpoints` (`game`,`gamenaam`,`playerid`,`pointscollected`) select `tblplayers`.`game`, 'fps', `tblplayers`.`id`, 0      `tblplayers`     left join `tblplayerpoints` on `tblplayers`.`id` = `tblplayerpoints`.`playerid` , `tblplayers`.`game` = `tblplayerpoints`.`game`  `tblplayers`.`game`='" . $gamenumber. "' , `tblplayers`.`joined`='1' , `tblplayerpoints`.`pointescollected` null 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -