|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46182 mysql_connection_reused( $link) function
Submitted: 2008-09-26 13:24 UTC Modified: 2011-01-06 16:06 UTC
From: ninzya at inbox dot lv Assigned: mysql (profile)
Status: Wont fix Package: MySQL related
PHP Version: 5.3.0alpha2 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ninzya at inbox dot lv
New email:
PHP Version: OS:


 [2008-09-26 13:24 UTC] ninzya at inbox dot lv
It would be great if we had mysql_connection_reused( $link) function, 
which returned boolean value if just established connection was 
reused or no.

Reproduce code:
$link =mysql_pconnect( $host .':' .$port, $user, $pass);
if( !mysql_connection_reused( $link)) {
  mysql_query( 'SET NAMES utf8;');
  mysql_query( 'USE mydb;');
} else {
  // connection was reused, don't do any initialization queries,
  //  because they were already made by another request

Expected result:
This would allow to optimize database load on heavy loaded servers.

Actual result:
Not implemented


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 23:45 UTC]
-Package: Feature/Change Request +Package: MySQL related
 [2011-01-06 16:06 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: mysql
 [2011-01-06 16:06 UTC]
Reusing of not properly cleaned up persistent connections is an evil aside effect that's confusing many beginners. mysqli gives you the choice if you want connections that are put into the persistent pool always to be cleaned up  and appear as if they had been just opened (default) or to return them in the state the previous user as left them when the connection was put into the persistent pool - with all the dirty side effects: authentication changes are not detected, transactions can be open, variables are not cleared up, temporary tables are there etc. . mysqli makes a clear cut and calls mysql_change_user() (C API = mysqli_change_user() PHP mysqli) before reusing a connection. Its always cleaned up. That's a safe choice for 90% of the users. Only some power users who know what they do should require the ext/mysql behaviour. And those power users don't need an extra API call because you can hack something using SQL connection variables:

SELECT @connection_init
if @connection_init = 0
  INIT stuff
  SET @connection_init = 1
 [2011-01-09 11:59 UTC] ninzya at inbox dot lv
Thank you for the info.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Feb 26 09:01:26 2024 UTC