Jump to content

mysql_connect always returns same Resource ID


anon_login_001

Recommended Posts

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?

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?

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!

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

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