Gayner Posted November 17, 2009 Share Posted November 17, 2009 mysql_query("INSERT INTO `forum_replies` (`tid`,`uid`,`message`,`date`,`time`) VALUES('".$tid."','".$_SESSION['user_id']."','".$msg."','".$date."','".$time."')"); mysql_query("UPDATE forum_topics SET `time`='".time()."', ". "lastposttime='" .time() ."' ". "WHERE id='" .$tid ."'") or die(mysql_error()); mysql_close(); header("Location: ./index.php?act=topic&id=".$tid); Iuno that's best code I can think off. whenever i run that on a form like The queries work it's jsut it takes like 5-10 seconds to freakin submit the dam thing? normal ?? Should be instant? my other forum if u submit it it's instant.. why this all slow?? Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 17, 2009 Share Posted November 17, 2009 Could be the server...Are the page loads slower on there compared to the other? Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 Could be the server...Are the page loads slower on there compared to the other? I mean, does the insert query look fine? And does this pic look fine too if not tell me what i need to fix to speed it up.. only if it's noticable. Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 I mean it literally takes 20seconds for it submit, lol but if i take that query out and press submit my update query works fine.. it's the insert i know for sure Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 17, 2009 Share Posted November 17, 2009 By just glancing at the query it seems to be fine to me but there could be something else causing the query to be slow. It may be something else on the page, its hard to say without know what is going on. You can try this cleaner looking query and see if it helps any: mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('$tid','".$_SESSION['user_id']."','$msg','$date','$time')"); Not going to say it will be any faster but it at least looks nicer lol. Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 By just glancing at the query it seems to be fine to me but there could be something else causing the query to be slow. It may be something else on the page, its hard to say without know what is going on. You can try this cleaner looking query and see if it helps any: mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('$tid','".$_SESSION['user_id']."','$msg','$date','$time')"); Not going to say it will be any faster but it at least looks nicer lol. I Replaced it with a random one mysql_query("INSERT INTO `prays` (`title`,`prayer`,`private`,`level`,`time`,`nameid`) VALUES ( '". mysql_real_escape_string('1') ."', '". mysql_real_escape_string('2') ."', '". mysql_real_escape_string('3') ."', '". mysql_real_escape_string('4') ."', '". mysql_real_escape_string('5') ."', '". mysql_real_escape_string('6') ."');") or die(mysql_error()) ; and it works perfect, but this is on a different table, is there something wrong my forum_replies table I posted a screenshot... hmm ??? Quote Link to comment Share on other sites More sharing options...
joel24 Posted November 17, 2009 Share Posted November 17, 2009 you could try seeing how long the query takes.. i.e. function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $time_start = getmicrotime(); mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('$tid','".$_SESSION['user_id']."','$msg','$date','$time')"); $time_end = getmicrotime(); $time = $time_end - $time_start; echo "Query took $time seconds"; Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 Query took 8.80006599426 seconds LOL but if i switch back to: mysql_query("INSERT INTO `prays` (`title`,`prayer`,`private`,`level`,`time`,`nameid`) VALUES ( '". mysql_real_escape_string('1') ."', '". mysql_real_escape_string('2') ."', '". mysql_real_escape_string('3') ."', '". mysql_real_escape_string('4') ."', '". mysql_real_escape_string('5') ."', '". mysql_real_escape_string('6') ."');") or die(mysql_error()) ; It only takes: Query took 0.000324964523315 seconds WTH?? It has to be something to do with my table forum_replies.. iuno wth omg Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 17, 2009 Share Posted November 17, 2009 The table looks fine. It could be the amount of data in the table but I doubt it. One thing I did notice is that you are storing the date as a varchar. I am not sure why you are doing that because you can use either mysql's date or datetime or even php's time(); functions to store the time. I usually use php's time() function with an int as the field type. Its really easy to work with timestamps and you can even get dates from them. Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 The table looks fine. It could be the amount of data in the table but I doubt it. One thing I did notice is that you are storing the date as a varchar. I am not sure why you are doing that because you can use either mysql's date or datetime or even php's time(); functions to store the time. I usually use php's time() function with an int as the field type. Its really easy to work with timestamps and you can even get dates from them. Hmm... true.. But I dont think any of this is worth 8seconds of insert query timeout? Can u please help me catch this problem bro.. thx Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 The table looks fine. It could be the amount of data in the table but I doubt it. One thing I did notice is that you are storing the date as a varchar. I am not sure why you are doing that because you can use either mysql's date or datetime or even php's time(); functions to store the time. I usually use php's time() function with an int as the field type. Its really easy to work with timestamps and you can even get dates from them. Hmm... true.. But I dont think any of this is worth 8seconds of insert query timeout? Can u please help me catch this problem bro.. thanks Sorry it wont let me edit. but this is the query not the update function one. mysql_query("INSERT INTO `forum_replies` (`tid`,`uid`,`message`,`date`,`time`) VALUES('".$tid."','".$_SESSION['user_id']."','".$msg."','".$date."','".$time."')"); Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted November 17, 2009 Share Posted November 17, 2009 You could try echoing out your query to see what is actually going into the query to see if there is anything unexpected in there. Quote Link to comment Share on other sites More sharing options...
joel24 Posted November 17, 2009 Share Posted November 17, 2009 try this and see how it goes for time... you don't have any triggers etc set up in your mysql database? function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $time_start = getmicrotime(); mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('1','2','3','4','5')"); $time_end = getmicrotime(); $time = $time_end - $time_start; echo "Query took $time seconds"; Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 try this and see how it goes for time... you don't have any triggers etc set up in your mysql database? function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $time_start = getmicrotime(); mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('1','2','3','4','5')"); $time_end = getmicrotime(); $time = $time_end - $time_start; echo "Query took $time seconds"; here: Query took 6.25345611572 seconds and in database looks like this: It insert data fine but took 7seconds lawl.. wat the hell is this mean? Indexes: Documentation Keyname Type Cardinality Action Field PRIMARY PRIMARY 102 Edit Drop id Im looking at Structure and I see Cardinality is 102? Even tho that wont make a difference but what the hell is wrong with my table, lol If this make any difference this was the query i oringally used to make the table CREATE TABLE `forum_replies` ( `id` int(11) NOT NULL auto_increment, `tid` int(11) NOT NULL, `uid` int(11) NOT NULL, `message` text NOT NULL, `date` varchar(64) NOT NULL, `time` int(25) NOT NULL, `edit_time` int(24) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ENGINE=InnoDB is this why? Charset=Latin1 is this problem too ? lol I think InnoDB Is the proble, how do i change it back tonormal mysql in phpmyadmin ? Quote Link to comment Share on other sites More sharing options...
trq Posted November 17, 2009 Share Posted November 17, 2009 Why are you trying to insert strings into int fields? Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 I think i need to change my storange engine. IM at phpmyadmin Operations should i use? MyIASM is best right ? I been using InnoDB and I think that is why so slow? Thorpe is is that really all u can say Mr +Hidden Quote Link to comment Share on other sites More sharing options...
Gayner Posted November 17, 2009 Author Share Posted November 17, 2009 ROFLMAO@@@@ I FIXED IT YES SIR GAYNER Changd all Engine types from INNODB TO MYSIAM.. HELLA FASTER OMG! THANKS, TOPIC SOLVED. NOW I NEED HELP ON THIS: http://www.phpfreaks.com/forums/index.php/topic,277182.0.html PLZ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.