anon_login_001 Posted July 7, 2008 Share Posted July 7, 2008 I have a situation where an index.php makes a database connection and thru templating/parameters certain other 'pages' are loaded as content, running their own queries, etc. If I open several links all at once (different tabs in IE7/FF) the pages seem to be waiting for the ones before to finish. I seem to have proven this by echo'ing out the Resource ID returned by mysql_connect() at the top of index.php each time. Even when that particular connection is busy (long running SELECT query) PHP always returns the same Resource ID... so all of the pages I try to access are basically waiting in line for the others to finish. This happens on a per-client basis... as in, I have another person right next to me, on a different machine, do the same thing I do... they get their own connect/resource ID, and I get mine... I *am* using the $new_link option, as such: mysql_connect($dbHostName, $userName, $password, true); Any ideas? Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/ Share on other sites More sharing options...
ag3nt42 Posted July 7, 2008 Share Posted July 7, 2008 check your connection limit in your SQL database. it may be set to only allow a single connection per ip Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583882 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Author Share Posted July 7, 2008 Using MySQL. I'm positive that connections-per-IP is not the problem. Viewing MySQL Administrator now, I see several idle connections from the server, one from my machine running a query browser, one from my machine running the MySQL Administrator program, etc. Also, relevant server settings: max_connections = 100 max_user_connections = 0 [unlimited] Anything else I should be looking at? Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583886 Share on other sites More sharing options...
ag3nt42 Posted July 7, 2008 Share Posted July 7, 2008 i'm not sure about this one... what if you close the connection each time? Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583888 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Author Share Posted July 7, 2008 Dealing with some slow queries in this case... the "close" wouldn't take effect until the query/script finished. Current problem is that queries are waiting in line anyway - I need more connections to open. I'm going to experiement with opening a seperate script to see if this is somehow related to the fact that all connections are being opened by index.php (even though they're being opened in seperate tabs/windows). Perhaps it's a per-script thing... which could be either PHP or Apache doing this. I'll post back what I find... in the mean time, any other ideas or questions are welcome. I'm a bit desperate to figure this out. Thanks! Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583898 Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2008 Share Posted July 7, 2008 Web servers are stateless. All the resources (unless you are using a persistent database connection) used on any requested page are destroyed when the code on that page ends execution. The resource ID is just an identifier. It is local to that invocation of the page. If you are getting a number like 4, that just means that it is the 4th resource used at that point on that page. Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583899 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Author Share Posted July 7, 2008 Thanks for clearing up the Resource ID thing. I thought that it might have been related directly with the particular MySQL connection I was using. Watching the Server Connections page of the MySQL Administrator shows several connections, but despite my many tabs/windows, only one connection (per client to the index.php page) is ever opened, and I watch it run one query after the other on the same connection. Trying to track down what's causing that. Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583904 Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2008 Share Posted July 7, 2008 Reviewing your posts - the new link parameter only affects what is happening in one invocation of a page. If in one script you had two mysql_connect() statements with the same parameters, a true value would cause a second link to be created instead of reusing the existing one. Is $dbHostName actually 'localhost' or are you using an IP or actual hostname? The reason I ask is - Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost".This could have something to do with only getting a single connection for multiple concurrent requests instead of each request opening a new connection. Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583915 Share on other sites More sharing options...
anon_login_001 Posted July 7, 2008 Author Share Posted July 7, 2008 Host is specified as an IP address. Also, I suppose I should have mentioned, the MySQL server is running on SuSE linux, as well the Apache server. Link to comment https://forums.phpfreaks.com/topic/113622-mysql_connect-always-returns-same-resource-id/#findComment-583924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.