Hi guys. I have an idea for my PHP/MySQL project. I wanted to get some feedback on it to see if it's even a good idea, or if I'm ever making the correct assumptions based on what I've read.
I've read that mysql_pconnect creates a persistent connection to the mysql database. I can see it's usefulness in that it would not have to take the processing time to connect to the database again everytime the user opens a new page. Of course, the downfall is that the persistent connection stays open until it times out. What I think I've come up with is a way to make sure the user does not create multiple connections.
I authenticate my user with a standard mysql_connect (non persistent). If the username and password are valid, then I create a persistent connection for that user and store the link identifier in a session variable. Everytime the user tries to execute a query, it uses that link identifier, checks if it is timedout, and if so, creates a new one. What I'd also like to do is store the link identifier in a session_data table in the database. What I'm thinking of doing is if the user logs out and logs right back in, when I am authenticating the user with standard mysql_connect, I can grab the link identier information from the database and assign it to the session variable. Like I said, in my Query() function, if the link identifier is bad, it will just create a new one. So long story short, if the user logs out and logs right back in, it will attempt to use the link identifier create on the last login, if that one has timed out, then it creates a new one.
Will this work? Have I made any bad assumptions about persistent connections?
Another question, I have read that persistent connection cannot be shared between multiple logged in users from different locations. It sounds like this is because of the how the processes are handled on most webservers. So even if every persistent connection I create uses the same connection information, a unique persistent connection is created for each 'web server process' correct? So if I use the method I've mentioned above, a persistent connection should be created for each logged in user (and only one connection). Correct?
Thanks in advance for all the help guys.