Azu Posted July 4, 2007 Share Posted July 4, 2007 Hello I use mysql_pconnect but still every page gets 8ms loading time added on to it from the mysql_pconnect Is there a way to fix it so that it doesn't have to reconnect every time, so that it won't add to page loading time? Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/ Share on other sites More sharing options...
scarhand Posted July 4, 2007 Share Posted July 4, 2007 Hello I use mysql_pconnect but still every page gets 8ms loading time added on to it from the mysql_pconnect Is there a way to fix it so that it doesn't have to reconnect every time, so that it won't add to page loading time? try just using 1 file with a switch and cases for your pages. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-289536 Share on other sites More sharing options...
Azu Posted July 4, 2007 Author Share Posted July 4, 2007 I'm sorry I don't understand.. How can I use a switch and cases to speed up mysql_pconnect? Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-289628 Share on other sites More sharing options...
Azu Posted July 6, 2007 Author Share Posted July 6, 2007 ????? Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-290986 Share on other sites More sharing options...
Azu Posted July 6, 2007 Author Share Posted July 6, 2007 Bump.. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291333 Share on other sites More sharing options...
jscix Posted July 6, 2007 Share Posted July 6, 2007 You shouldn't have that loading time, usually mysql queries are relatively fast.. anyway.. assuming it's just the sql-server lagging.. depending on the kind of data you are retreiving.. grab all the data that your scripts will require on the first connection and set all the data into session variables. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291336 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 Why are you using pconnect? From what I know it is unnecessary and takes a toll on your server. There is nothing wrong with closing mysql connections and re-opening them on the page call. Using that pconnect, if you had 100 users your site may stop functioning because of it. Unless there is a specific reason for using it I would stray away from it and just use the regular mysql_connect. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291338 Share on other sites More sharing options...
Azu Posted July 6, 2007 Author Share Posted July 6, 2007 I thought that using pconnect instead of normal connect made it so that it doesn't have to keep reconnecting. But either way it adds an extra 8ms to page generation. How can I fix it so that it doesn't have to keep connecting over and over and over and over so that it is just always connected so that there is no more needing to keep connecting and slowing down the page loading every time? And yes 8ms is a lot when the average time it takes to generate the page is ~16ms and there is a lot of traffic. It would be cutting the load in half if I could get rid of that. Please tell me how I can. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291547 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 Post some of your code. I use mysql_connect and my page load is very low. It sounds like you are running a lot of unnecessary trips to the database. The goal is to get as much as you can in one query and than use PHP to process it. Also using * is less efficient in defining the column names etc. It sounds like it is more of a coding issue than something that can be solved by using a single connection. Unless you are connecting to remote database server. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291549 Share on other sites More sharing options...
Azu Posted July 9, 2007 Author Share Posted July 9, 2007 Sorry I think I didn't explain it right. What I meant was, the mysql_connect is taking as long as everything else in the page put together. So it is making it take twice as much load. So I am wandering how can I make it so that PHP just stays connected to it so that it doesn't have to keep reconnecting on every page load. I THOUGHT that this was what mysql_pconnect was for but now I think I was wrong because it does not make any differance then using mysql_connect. So ya basically I just want my website to always have a single connection to mysql open all the time so that it doesn't have to keep reconnecting on every page load. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-293226 Share on other sites More sharing options...
soycharliente Posted July 9, 2007 Share Posted July 9, 2007 Does this help? http://www.phpfreaks.com/phpmanual/page/features.persistent-connections.html Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-293236 Share on other sites More sharing options...
Azu Posted July 11, 2007 Author Share Posted July 11, 2007 Thanks, I already tried that though and it didn't make a differance.. Try <?$a=array_sum(explode(' ',microtime())); mysql_connect(localhost,"root","password"); echo'MYSQL connection time:'.round(round(array_sum(explode(' ',microtime()))-$a,5)*1000,1).' milliseconds';?> And then try replacing the mysql_connect with mysql_pconnect and refresh a few times It always takes 8 milliseconds on every page load no matter which one I use T_T please tell me how I can fix it.. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-295115 Share on other sites More sharing options...
Azu Posted July 12, 2007 Author Share Posted July 12, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-296818 Share on other sites More sharing options...
Azu Posted July 13, 2007 Author Share Posted July 13, 2007 BUMP Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-297267 Share on other sites More sharing options...
Azu Posted July 14, 2007 Author Share Posted July 14, 2007 bump................... Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-298111 Share on other sites More sharing options...
Azu Posted July 16, 2007 Author Share Posted July 16, 2007 Bump Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299124 Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 Unless you know you specifically need mysql_p* (and you dont) don't use them. 8 secons is rediculous but it sounds more a server or network issue rather than something your going to fix in your code. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299134 Share on other sites More sharing options...
rameshfaj Posted July 16, 2007 Share Posted July 16, 2007 Was it OK when only using mysql_connect()?How much time did it took? If the time was comparatively similar then there is no problem with the persistent connection. But I think persistent connection gives some problem to you in future also.Like too many connections,server refused to establish the connection. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299144 Share on other sites More sharing options...
Azu Posted July 16, 2007 Author Share Posted July 16, 2007 Bump =\ Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299262 Share on other sites More sharing options...
Azu Posted July 16, 2007 Author Share Posted July 16, 2007 mysql_connect and mysql_pconnect are both doubling the time it takes for my PHP scripts to run. They take 8ms each no matter what I do. Please help :X Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299569 Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 Stop bumping this thread. 8ms is not what I would call an issue, if you think it is, look at the network connection between your webserver and db server. There isn't really anything you can do in your code. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299573 Share on other sites More sharing options...
per1os Posted July 16, 2007 Share Posted July 16, 2007 Unless you know you specifically need mysql_p* (and you dont) don't use them. 8 secons is rediculous but it sounds more a server or network issue rather than something your going to fix in your code. It has to be your network, as Thorpe said. Contact the server administrator. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299598 Share on other sites More sharing options...
Azu Posted July 17, 2007 Author Share Posted July 17, 2007 Okay sorry I don't know who to contact though since I'm running this all by myself. But anyways, when all the queries put together take less then 4ms, and it takes PHP about 3MS to process the page not counting the mysql stuff, and 8MS is being wasted on every page generation, that more then doubles server load, meaning less then half as much traffic can be handled. Please tell me how I can fix it so that it doesn't take so (relatively) long. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-300514 Share on other sites More sharing options...
per1os Posted July 17, 2007 Share Posted July 17, 2007 Okay sorry I don't know who to contact though since I'm running this all by myself. But anyways, when all the queries put together take less then 4ms, and it takes PHP about 3MS to process the page not counting the mysql stuff, and 8MS is being wasted on every page generation, that more then doubles server load, meaning less then half as much traffic can be handled. Please tell me how I can fix it so that it doesn't take so (relatively) long. How good of a computer are you running it on? Process speed, memory what type of OS are you using? Very well what could be happening is you do not have enough memory on your computer to make it work faster. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-300520 Share on other sites More sharing options...
drewbee Posted July 17, 2007 Share Posted July 17, 2007 The speed shouldn't be affected that much by pconnect. All that does is it tries and uses an existing connection. Your lag will be coming from the database and returning of data, not the inital connection. Quote Link to comment https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-300527 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.