php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #12985 mysql_connect() forces reuse of the connection
Submitted: 2001-08-27 20:47 UTC Modified: 2002-07-16 03:39 UTC
From: vedad at kajtaz dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: not os related
Private report: No CVE-ID: None
 [2001-08-27 20:47 UTC] vedad at kajtaz dot net
Hi all,

i've just discovered that mysql_connect() uses a hash that forces it to reuse a connection on a second call to mysql_connect() with the same arguments, instead of opening a new connection.
This was, at least for me, an unexpected behaviour: i was hoping to be able to use several database connections to the same mysql server (and same user) in order to be able to issue several LOCK TABLE or GET_LOCK() queries (mysql allows only one 'active' lock per connection)

[I know basic locking may be done on php server's system level, but it doesn't make sense in web-cluster environment, and using a database to centralize locks sounds interesting]

I also took a look into php's mysql api source (i'm not familiar with php sources), and adding an optional argument saying _not_ to reuse a connection or coding an alternative mysql_connect() from the existing one doesnt _seem_ to be a long or complicated task.

I _might_ do the change myself for my server, but as the sites i'm working on are unlikely to be hosted on my server, this is not very portable and would be probably useless.

Please tell me what you think about this issue, and if a change to mysql_connect() function is conceivable (in that case i'd be glad to do the change myself and send you the result :)

Thanks
-- vedad

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-27 22:45 UTC] joey@php.net
What is different between what you are asking for
and mysql_pconnect()?

http://www.php.net/msyql-pconnect
 [2001-08-27 22:47 UTC] joey@php.net
Nevermind...I read this whole report backwards. I thought
you were looking for persistence, not trying to get rid
of it. Apologies.
 [2001-08-28 05:03 UTC] mfischer@php.net
Vedad,

I had exactly the same issue back a few months. Actually I made such a patch and sent it to Zeev, unfortunately he didn't included it. And, you're right, the patch is trivial.

- Markus
 [2001-08-28 05:27 UTC] vedad at kajtaz dot net
Thank you Markus, i don't feel alone any more :-)

By the way after a little bit of reflection and yamba, maybe a configure option (that defaults to current behaviour) would be more suitable, rather than modifying the mysql api and the docs (i understand that this might confuse a lot of developers).
I beleive this would have no impact on php users (devs),  only system admins would be concerned (and cpu cycles loss would probably be microscopic).

please consider this :)

later
-- vedad
 [2002-07-16 03:39 UTC] georg@php.net
Since 4.2.0 you have an additonal parameter new_link which 
forces mysql_connect to open a new link.

See: 
http://www.php.net/manual/en/function.mysql-connect.php 
for more details

 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 15:05:45 2022 UTC