Bug #79661 [Fbk->Asn]: 2 Connections with different buffer stats cant run
| From: | thebluewalrus at gmail dot com | Date: | Mon, 01 Jun 2020 15:44:17 +0000 |
| Subject: | Bug #79661 [Fbk->Asn]: 2 Connections with different buffer stats cant run | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227264@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79661&edit=1
ID: 79661
User updated by: thebluewalrus at gmail dot com
Reported by: thebluewalrus at gmail dot com
Summary: 2 Connections with different buffer stats cant run
-Status: Feedback
+Status: Assigned
Type: Bug
Package: PDO MySQL
Operating System: Amazon Linux release 2 (Karoo)
PHP Version: 7.3.18
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Thanks. That worked, I think the documentation should be updated in this case. All documentation
I've seen has it used as a boolean value.
Previous Comments:
------------------------------------------------------------------------
[2020-06-01 15:31:45] cmb@php.net
Instead of setting PDO::ATTR_PERSISTENT to true, you can set it to
some arbitrary key; connections with different persistence keys
will be separate. In your case, maybe use something like
'buffered' and 'unbuffered', respectively.
------------------------------------------------------------------------
[2020-06-01 15:13:06] thebluewalrus at gmail dot com
Description:
------------
If 2 PDO connections are opened they seem to be merged.
If the first is using unbuffered and second using buffered the first results in a buffered return.
If both connections are using unbuffered and the first connection is running the second connection
returns:
Cannot execute queries while other unbuffered queries are active. Consider using
PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you
may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
on the first call.
Issue produces on machines running 7.3.17 (OS Amazon Linux release 2 (Karoo)) and 7.1.33 (OS Red Hat
Enterprise Linux Server release 7.3 (Maipo)).
Test script:
---------------
Case 1:
$db = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass,
array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));
$db_ub = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass,
array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$stmt = $db->prepare('A QUERY THAT WILL EXCEED MEMORY LIMIT IF ALL ROWS RETURNED');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
//should run out of memory
}
Case 2:
$db = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass,
array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));
$db_ub = new PDO("mysql:host=".$dbhost.";dbname=".$dbname, $dbuser, $dbpass,
array(PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));
$stmt = $db->prepare('A QUERY THAT WILL EXCEED MEMORY LIMIT IF ALL ROWS RETURNED');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$stmt = $db_ub->prepare('select now()');
$stmt->execute();
}
Expected result:
----------------
$stmt should only have 1 row at a time and memory usage should be low
Actual result:
--------------
Usually results in PHP Fatal error: Allowed memory size ...
ini_set('memory_limit', can be used to get the script to run.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79661&edit=1