Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-289536
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291336
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291338
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291547
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-291549
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-293226
Share on other sites

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..

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-295115
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299144
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-299598
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-300514
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/58386-persistant-mysql/#findComment-300520
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.