Bug #54181 [Bgs]: MySQLi doesn't always reuse persistent link inside same script

2011-03-08 Thread carsten_sttgt at gmx dot de
Edit report at http://bugs.php.net/bug.php?id=54181&edit=1

 ID: 54181
 User updated by:carsten_sttgt at gmx dot de
 Reported by:carsten_sttgt at gmx dot de
 Summary:MySQLi doesn't always reuse persistent link inside
 same script
 Status: Bogus
 Type:   Bug
 Package:MySQLi related
 PHP Version:Irrelevant
 Block user comment: N
 Private report: N

 New Comment:

> MySQL should behave the same but is probably affected

> by the new_link parameter



Ok, this one I can understand (I think...)



| $con1 = mysqli_connect('localhost', 'foo', '');

| $con2 = mysqli_connect('localhost', 'foo', '');

is resulting in 2 connections, so:

| $con1 = mysqli_connect('p:localhost', 'foo', '');

| $con2 = mysqli_connect('p:localhost', 'foo', '');

is also resulting in 2 connections.



| $con1 = mysql_connect('localhost', 'foo', '');

| $con2 = mysql_connect('localhost', 'foo', '');

is resulting in 1 connections, so:

| $con1 = mysql_pconnect('localhost', 'foo', '');

| $con2 = mysql_pconnect('localhost', 'foo', '');

is also resulting in 1 connections.

(no new_link)





But what's with PDO_MySQL?

| $con1 = new PDO('mysql:host=localhost', 'foo', '');

| $con2 = new PDO('mysql:host=localhost', 'foo', '');

is resulting in 2 connections, but:



| $con1 = new PDO('mysql:host=localhost', 'foo', '',

| array(PDO::ATTR_PERSISTENT => true));

| $con2 = new PDO('mysql:host=localhost', 'foo', '',

| array(PDO::ATTR_PERSISTENT => true));

is resulting in 1 connections.



Thus this "bug" should be assigned to PDO/PDO_MySQL? (Maybe as change
request).

Or as "Doc" for MySQLi/PDO how this is working in detail.





BTW:

I think there should be consequent behavior how thinks are working. Or a
better description how a extension is working.  For mysql_pconnect there
is an exact description:

| First, when connecting, the function would first try to find a
(persistent)

| link that's already open with the same host, username and password. If
one

| is found, an identifier for it will be returned instead of opening a
new

| connection.


Previous Comments:

[2011-03-08 09:34:39] scott...@php.net

The problem with using the same connection twice is that with unbuffered
results 

you can't run more than query at once. MySQLi only puts a connection up
for availability until after its done with it.



MySQL should behave the same but is probably affected by the new_link
parameter 

which returned the same connection if all the parameters matched. It
wasn't 

persistance just an optimization that caused more confusion than
anything else.


[2011-03-07 19:53:34] carsten_sttgt at gmx dot de

> This is working as expected, persistent connections are only

> re-used if they're no longer in use by another script.



OK, with "another Script" you also mean the same script. Just to
recapitulate:

| 



$con1 is already in use, so $con2 will results in a second connection.



If this is the expected behavior, why is this script:

|  true)

| );

| $con2 = new PDO(

| 'mysql:host=localhost',

| 'foo', '',

| array(PDO::ATTR_PERSISTENT => true)

| );

| ?>



or

| 



resulting in 1 connection? $con1 is already in use, but $con2 is using
the same connection as $1.


[2011-03-07 17:28:31] scott...@php.net

This doesn't have anything to do with persistent connections, with
mysql_connect() 

if you open a connection with the same parameters it won't return a new
link 

unless you set the 4th parameter to true.



This is working as expected, persistent connections are only re-used if
they're no 

longer in use by another script.


[2011-03-07 15:10:49] carsten_sttgt at gmx dot de

Description:

If I open an existing persistent link a second (or 3rd, ...) time inside
the same script, MySQLi is only reusing the existent link if I have
explicitly closed the link before. At the moment it's always creating a
new link.



With MySQL it's working as expected.



 

Test script:
---
thread_id);

$con2 = mysqli_connect('p:localhost', 'foo', '');

var_dump($con2->thread_id);

mysqli_close($con1);

mysqli_close($con2);



echo "---\n";



$con3 = mysqli_connect('p:localhost', 'bar', '');

var_dump($con3->thread_id);

mysqli_close($con3);

$con4 = mysqli_connect('p:localhost', 'bar', '');

var_dump($con4->thread_id);

mysqli_close($con4);



echo "===\n";



$con5 = mysql_pconnect('localhost', 'foo', '');

var_dump(mysql_thread_id($con5));

$con6 = mysql_pconnect('localhost', 'foo', '');

var_dump(mysql_thread_id($con6));

mysql_close($con5);

mysql_close($con6);



echo "---\n";



$con7 = mysql_pconnect(

Bug #54181 [Bgs]: MySQLi doesn't always reuse persistent link inside same script

2011-03-08 Thread scottmac
Edit report at http://bugs.php.net/bug.php?id=54181&edit=1

 ID: 54181
 Updated by: scott...@php.net
 Reported by:carsten_sttgt at gmx dot de
 Summary:MySQLi doesn't always reuse persistent link inside
 same script
 Status: Bogus
 Type:   Bug
 Package:MySQLi related
 PHP Version:Irrelevant
 Block user comment: N
 Private report: N

 New Comment:

The problem with using the same connection twice is that with unbuffered
results 

you can't run more than query at once. MySQLi only puts a connection up
for availability until after its done with it.



MySQL should behave the same but is probably affected by the new_link
parameter 

which returned the same connection if all the parameters matched. It
wasn't 

persistance just an optimization that caused more confusion than
anything else.


Previous Comments:

[2011-03-07 19:53:34] carsten_sttgt at gmx dot de

> This is working as expected, persistent connections are only

> re-used if they're no longer in use by another script.



OK, with "another Script" you also mean the same script. Just to
recapitulate:

| 



$con1 is already in use, so $con2 will results in a second connection.



If this is the expected behavior, why is this script:

|  true)

| );

| $con2 = new PDO(

| 'mysql:host=localhost',

| 'foo', '',

| array(PDO::ATTR_PERSISTENT => true)

| );

| ?>



or

| 



resulting in 1 connection? $con1 is already in use, but $con2 is using
the same connection as $1.


[2011-03-07 17:28:31] scott...@php.net

This doesn't have anything to do with persistent connections, with
mysql_connect() 

if you open a connection with the same parameters it won't return a new
link 

unless you set the 4th parameter to true.



This is working as expected, persistent connections are only re-used if
they're no 

longer in use by another script.


[2011-03-07 15:10:49] carsten_sttgt at gmx dot de

Description:

If I open an existing persistent link a second (or 3rd, ...) time inside
the same script, MySQLi is only reusing the existent link if I have
explicitly closed the link before. At the moment it's always creating a
new link.



With MySQL it's working as expected.



 

Test script:
---
thread_id);

$con2 = mysqli_connect('p:localhost', 'foo', '');

var_dump($con2->thread_id);

mysqli_close($con1);

mysqli_close($con2);



echo "---\n";



$con3 = mysqli_connect('p:localhost', 'bar', '');

var_dump($con3->thread_id);

mysqli_close($con3);

$con4 = mysqli_connect('p:localhost', 'bar', '');

var_dump($con4->thread_id);

mysqli_close($con4);



echo "===\n";



$con5 = mysql_pconnect('localhost', 'foo', '');

var_dump(mysql_thread_id($con5));

$con6 = mysql_pconnect('localhost', 'foo', '');

var_dump(mysql_thread_id($con6));

mysql_close($con5);

mysql_close($con6);



echo "---\n";



$con7 = mysql_pconnect('localhost', 'bar', '');

var_dump(mysql_thread_id($con7));

mysql_close($con7);

$con8 = mysql_pconnect('localhost', 'bar', '');

var_dump(mysql_thread_id($con8));

mysql_close($con8);



?>



Expected result:

int(1)

int(1)

---

int(2)

int(2)

===

int(3)

int(3)

---

int(4)

int(4)

Actual result:
--
int(1)

int(2)

---

int(3)

int(3)

===

int(4)

int(4)

---

int(5)

int(5)






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54181&edit=1


Bug #54181 [Bgs]: MySQLi doesn't always reuse persistent link inside same script

2011-03-07 Thread carsten_sttgt at gmx dot de
Edit report at http://bugs.php.net/bug.php?id=54181&edit=1

 ID: 54181
 User updated by:carsten_sttgt at gmx dot de
 Reported by:carsten_sttgt at gmx dot de
 Summary:MySQLi doesn't always reuse persistent link inside
 same script
 Status: Bogus
 Type:   Bug
 Package:MySQLi related
 PHP Version:Irrelevant
 Block user comment: N
 Private report: N

 New Comment:

> This is working as expected, persistent connections are only

> re-used if they're no longer in use by another script.



OK, with "another Script" you also mean the same script. Just to
recapitulate:

| 



$con1 is already in use, so $con2 will results in a second connection.



If this is the expected behavior, why is this script:

|  true)

| );

| $con2 = new PDO(

| 'mysql:host=localhost',

| 'foo', '',

| array(PDO::ATTR_PERSISTENT => true)

| );

| ?>



or

| 



resulting in 1 connection? $con1 is already in use, but $con2 is using
the same connection as $1.


Previous Comments:

[2011-03-07 17:28:31] scott...@php.net

This doesn't have anything to do with persistent connections, with
mysql_connect() 

if you open a connection with the same parameters it won't return a new
link 

unless you set the 4th parameter to true.



This is working as expected, persistent connections are only re-used if
they're no 

longer in use by another script.


[2011-03-07 15:10:49] carsten_sttgt at gmx dot de

Description:

If I open an existing persistent link a second (or 3rd, ...) time inside
the same script, MySQLi is only reusing the existent link if I have
explicitly closed the link before. At the moment it's always creating a
new link.



With MySQL it's working as expected.



 

Test script:
---
thread_id);

$con2 = mysqli_connect('p:localhost', 'foo', '');

var_dump($con2->thread_id);

mysqli_close($con1);

mysqli_close($con2);



echo "---\n";



$con3 = mysqli_connect('p:localhost', 'bar', '');

var_dump($con3->thread_id);

mysqli_close($con3);

$con4 = mysqli_connect('p:localhost', 'bar', '');

var_dump($con4->thread_id);

mysqli_close($con4);



echo "===\n";



$con5 = mysql_pconnect('localhost', 'foo', '');

var_dump(mysql_thread_id($con5));

$con6 = mysql_pconnect('localhost', 'foo', '');

var_dump(mysql_thread_id($con6));

mysql_close($con5);

mysql_close($con6);



echo "---\n";



$con7 = mysql_pconnect('localhost', 'bar', '');

var_dump(mysql_thread_id($con7));

mysql_close($con7);

$con8 = mysql_pconnect('localhost', 'bar', '');

var_dump(mysql_thread_id($con8));

mysql_close($con8);



?>



Expected result:

int(1)

int(1)

---

int(2)

int(2)

===

int(3)

int(3)

---

int(4)

int(4)

Actual result:
--
int(1)

int(2)

---

int(3)

int(3)

===

int(4)

int(4)

---

int(5)

int(5)






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54181&edit=1