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:
| <?php
| $con1 = mysqli_connect('p:localhost', 'foo', '');
| $con2 = mysqli_connect('p:localhost', 'foo', '');
| ?>
$con1 is already in use, so $con2 will results in a second connection.
If this is the expected behavior, why is this script:
| <?php
| $con1 = new PDO(
| 'mysql:host=localhost',
| 'foo', '',
| array(PDO::ATTR_PERSISTENT => true)
| );
| $con2 = new PDO(
| 'mysql:host=localhost',
| 'foo', '',
| array(PDO::ATTR_PERSISTENT => true)
| );
| ?>
or
| <?php
| $con1 = mysql_pconnect('localhost', 'foo', '');
| $con2 = mysql_pconnect('localhost', 'foo', '');
| ?>
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] [email protected]
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:
---------------
<?php
$con1 = mysqli_connect('p:localhost', 'foo', '');
var_dump($con1->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